Django environment installed + site deployment (uwsgi+nginx)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Environment CentOS6.2,Django1.6,uwsgi1.9.20,nginx1.4.4




1.yum install mysql mysql-devel mysql-server


2.python
CentOS6.2 comes with python2.6.6, with Python did not install the setuptools component
When installing the python third party modules are the basic use of Python setup.py install command, so the need to install setuptools
> wget  
> python ez_setup.py --user

3.pip pip is a package management tool Python.


> wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz --no-check-certificate
>chmod +x pip-1.3.1.tar.gz

>tar xzvf pip-1.3.1.tar.gz
>cd pip-1.3.1
>python setup.py install


#After the installation, the PIP executable files in /root/.local/bin, LN to establish a connection to /bin


4.yum install python-devel


5.pip install MySQL-python
6.pip install django


The environment set up.


My project is/root/src/mysite
--mysite --settings --test1 --templates --html file --static --css
--images


Deployment
Install uwsgi
WebServerGatewayInterface
$ export LDFLAGS="-Xlinker --no-as-needed"
$ pip install uwsgi

Write django_wsgi.py file, put it in with the same directory file manage.py.
#!/usr/bin/env python
# coding: utf-8

import os
import sys

reload(sys)
sys.setdefaultencoding('utf8')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()



Execution
uwsgi --http :8000 --chdir /root/src/mysite --module django_wsgi

Can use ip:8000/xxx to access the
#This does not introduce static files, can access uwsgi no problem


Install nginx
To download the nginx.org website
nginx-1.4.4.tar.gz
Decompression
yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel
./configure
make install
Then
cp /usr/local/nginx/sbin/nginx /usr/bin
Start
nginx
#The default port is 80
#Direct access, shows the nginx welcome screen
Stop it
nginx -s stop
Restart
nginx -s reload






The configuration of nginx and Django
The establishment of wsgi.ini file in the MySite directory

Content
[uwsgi]
socket= 127.0.0.1:8001
chdir= /root/src/mysite
module= django_wsgi
buffer-size = 32768




Modify the nginx configuration file
Server modified into the following.
server {
listen 8000;
server_name 127.0.0.1;
autoindex on;
charset UTF-8;

access_log /root/src/logs/access.log;
error_log /root/src/logs/error.log;
client_max_body_size 75M;

location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
uwsgi_read_timeout 2;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control provate;
alias /root/src/mysite/test1/static;
}

#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;
}


}




*In the nginx.conf the first line of the file, plus
user root
#It is the default user permissions, not cause static files cannot reference




Configuration completed.
Start uwsgi
Into the /root/src/mysite directory.
Implementation of uwsgi -wsgi.ini
Then another console, execute the nginx start


The access to the ip:8000/url can access.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Elmer at February 11, 2014 - 11:30 AM