Operation can refer to http://www.linuxyw.com/353.html (Nginx+uwsgi+django+python Environment Deployment documentation)
Here are just a few of my configuration
Environment:
Nginx Version: 1.7.9
Django Version: 1.6.8
Python version: 2.7.5
Uwsgi version: 2.0.9
Install Mysql-python:
Best source installation, Yum install-y Mysql-python may fail due to path issue import MySQLdb:
http://sourceforge.net/projects/mysql-python/files/mysql-python/
Tar zxvf mysql-python-1.2.3.tar.gzcd mysql-python-1.2.3python setup.py Install
Path and structure diagram for the Django project:
(Fabric-bolt) [[email protected] fabric_bolt]# tree-d-L 3
'--Work |--MyWeb | '--static '--work
To create a Django project:
Project Location:/www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt/(there are already other Django apps under this path)
To create a project:
cd/www/fabric-bolt/lib/python2.7/site-packages/fabric_boltdjango-admin.py startproject Work
Configure Nginx:
Add the following to the Nginx configuration file:
Vim/usr/local/nginx/conf
location / { root /www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt/work; include uwsgi_params; uwsgi_pass 192.168.1.121:9000; uwsgi_param uwsgi_chdir /www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt/work; uwsgi_param UWSGI_SCRIPT django_wsgi; access_log /usr/local/nginx/logs/access.log; } location / static/ { alias /www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt /work/myweb/static/; index index.html;}
Work is the project name, Mynew is the app name
Configuration Uwsgi:
Add a Uwsgi configuration file to Nginx:
Vim/usr/local/nginx/conf/uwsgi.xml
<uwsgi><socket>192.168.1.121:9000</socket><pidfile>/usr/local/nginx/conf/uwsgi.pid< /pidfile><processes>2</processes><pythonpath>/www/fabric-bolt/lib/python2.7/site-packages </pythonpath> #注意, according to the original configuration/tmp/uwsgi.log always error "Importerror:no module named Django.core.handlers.wsgi", However, the Django path exists in Sys.path, and importing import django.core.handlers.wsgi on the python command line is normal, which is contradictory. What to do? Just add this sentence! When the Uwsgi is added,/tmp/uwsgi.log will prompt "added/www/fabric-bolt/lib/python2.7/site-packages/to pythonpath.", which is right! <module>django_wsgi</module><chdir>/www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt/ Work</chdir><daemonize>/tmp/uwsgi.log</daemonize></uwsgi>
To create a Django application module:
vim/www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt/work/django_wsgi.py
Import Os,sys#os.environ.setdefault ("Django_settings_module", "myweb.settings") #path = "/www/fabric-bolt/lib/ Python2.7/site-packages/fabric_bolt/work "#if path Not in Sys.path: # sys.path.insert (0,"/www/fabric-bolt/lib/ Python2.7/site-packages/fabric_bolt/work ") os.environ[" django_settings_module "] =" work.settings "Import Django.core.handlers.wsgiapplication = Django.core.handlers.wsgi.WSGIHandler ()
Access test:
The following interface appears, indicating that the configuration was successful
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/41/wKioL1Ss-HGjrj2tAADkiQtPiAw007.jpg "title=" a1.jpg "alt=" Wkiol1ss-hgjrj2taadkiqtpiaw007.jpg "/>
Copy a few pictures or HTML files into the/www/fabric-bolt/lib/python2.7/site-packages/fabric_bolt/work/myweb/static/directory, you can access:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/41/wKioL1Ss-ZjQYFxXAAEPgGFTQFg947.jpg "title=" a1.jpg "alt=" Wkiol1ss-zjqyfxxaaepggftqfg947.jpg "/>
Nginx+uwsgi Deploying a Django Project