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

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 install command, so the need to install setuptools
> wget  
> python --user

3.pip pip is a package management tool Python.

> wget --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 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

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

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

import os
import sys


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

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

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 website
yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel
make install
cp /usr/local/nginx/sbin/nginx /usr/bin
#The default port is 80
#Direct access, shows the nginx welcome screen
Stop it
nginx -s stop
nginx -s reload

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

chdir= /root/src/mysite
module= django_wsgi
buffer-size = 32768

Modify the nginx configuration file
Server modified into the following.
server {
listen 8000;
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_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