1.安装virtualenv,创建虚拟环境django15
sudo apt-get install virtualenv
virtualenv env
source bin/active
pip install django1.5.1
2.安装uwsgi
pip install uwsgi等
3.将tcweb拷贝到django15虚拟环境中,建立uwsgi配置
tc_uwsgi.ini
[uwsgi] vhost = false #注意多个项目的时候不能true哦,否则多个项目都共用这个配置参数了,这个很折腾人 plugins = python #socket = 127.0.0.1:9000 #这个注释掉了,我采用sock的方式,当然你可以使用端口方式,nginx配置的时候修改一下即可 socket = /opt/django15/proj_uwsgi.sock #配置文件用到的sock文件 master = true enable-threads = true workers = 2 #进程数 wsgi-file = /opt/django15/myproj/myproj/wsgi.py #这是项目wsgi.py文件的路径 virtualenv = /opt/django15/ #虚拟环境的路径 chdir = /opt/django15/tcweb #下myproject项目的路径
启动uwsgi
nohup uwsgi --ini myproj_uwsgi.ini --pidfile=./uwsgi-master.pid& #--pidfile指定进程
重启uwsgi
kill -TERM `cat ./uwsgi-master.pid`
4.nginx配置
server{ listen 8088; server_name tt.com; access_log /opt/django15/logs/access.log; error_log /opt/django15/logs/error.log; root /opt/django15/myproj; index index.html index.htm; charset utf-8; location ~^/static/ { root /opt/django15/myproj/; expires 24h; access_log off; } location ~^/media/ { root /opt/django15/myproj/; expires 24h; access_log off; } location /{ uwsgi_pass 127.0.0.1:9000; include uwsgi_params; #proxy_http_version 1.1; } }