Configure Nginx+uwsgi+django+mysql on VPS

Source: Internet
Author: User
Tags vps install django nginx server

1. Install Django See: http://djangobook.py3k.cn/2.0/chapter02/ 2. Install PIP

$ sudo apt-get install python-pip python-dev build-essential $ sudo pip install --upgrade pip $ sudo pip install --upgrade virtualenv$ sudo apt-get install libmysqld-dev

3. Install MySQL

$ apt-get install mysql-server

4. Installing Mysql-python

$ sudo easy_install mysql-python

5. Installing Uwsgi

$ add-apt-repository ppa:stevecrozz/ppa$ apt-get update  $ apt-get install uwsgi

6. Testing Uwsgi New test file

# test.pydef application(env, start_response):    start_response(‘200 OK‘, [(‘Content-Type‘,‘text/html‘)])    

Then execute:

uwsgi --http :8001 --wsgi-file test.py

You can see the results in the browser access http://youip:8001 7. Configure Django

django-admin.py startproject django_test    #创建一个Django项目

Write the django_wsgi.py file and place it in the same directory as the file manage.py.

#!/usr/bin/env python# coding: utf-8import osimport sys# 将系统的编码设置为UTF8reload(sys)sys.setdefaultencoding(‘utf8‘)os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_test.settings")from django.core.handlers.wsgi import WSGIHandlerapplication = WSGIHandler()

If your project directory is in/home/django_test, execute the command:

uwsgi --http :8000 --chdir /home/django_test --module django_wsgi

8. Configure Uwsgi to create a new XML file: Djangochina_socket.xml, put it in the/home/django_test/directory:

<uwsgi>    <socket>:8077</socket>    <chdir>home/django_test</chdir>    <module>django_wsgi</module>    <processes>4</processes> <!-- 进程数 -->     <daemonize>uwsgi.log</daemonize></uwsgi>

9. Installing Nginx

$ sudo apt-get install nginx

Start

$ sudo /etc/init.d/nginx start

10. Configure the Nginx Uwsgi Django Run Shell:

$ sudo vim /etc/nginx/sites-available/default

Add to:

server {    listen   90;    server_name local;    access_log /home/django_test/logs/access.log;    error_log /home/django_test/logs/error.log;    #charset koi8-r;    #access_log  logs/host.access.log  main;    location / {     include        uwsgi_params;     uwsgi_pass     127.0.0.1:8077;    }    #error_page  404              /404.html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }    location /static/ {        alias  /home/django_test/collectedstatic/;        index  index.html index.htm;    }    location /media/ {        alias  /home/django_test/public/media/;    }}

Note: Some folders in the configuration file need to be created yourself the implementation of 10.nginx+uwsgi+django restarts the Nginx server to make the Nginx configuration effective.

$sudo nginx -s  reload

Check the Nginx log for any exceptions after restarting. Start the UWSGI server

cd /home/django_testuwsgi -x djangochina_socket.xml

Check the log uwsgi.log for any unusual discoveries. Access to the service therefore, we visit the VPS ip:8090, if the discovery program and the individual use of the Django-initiated program is exactly the same, it means success! the method of shutting down the service kills the UWSGI process. Reference article: "Five steps to implement a Django program using the Nginx+uwsgi+django Method" (under) "Five steps to implement a Django program using the Nginx+uwsgi+django Method" (top) http:// Wiki.ubuntu.org.cn/nginx

Configure Nginx+uwsgi+django+mysql on VPS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.