1.安装nginx,参考http://blog.csdn.net/ljsbuct/article/details/8538968
2.安装uwsgi,参考http://blog.csdn.net/ljsbuct/article/details/8539833
3.安装django及其他,参考http://blog.csdn.net/ljsbuct/article/details/8351026
安装版本:nginx1.3.4+python2.7.3(系统自带)+django1.4.1+uWSGI1.2.5
参考:http://blog.sina.com.cn/s/blog_69b6a7c601014tsr.html
1.创建django project
2.创建nginx虚拟主机配置文件
cd /etc/nginx/conf.d
sudo vim xxx.conf
server {
listen 80;
server_name learner.com;
location / {
root /xxxxx/; #project 的路径
include uwsgi_params;
uwsgi_pass 127.0.0.1:9322; #端口号要与下文的uwsgi配置文件的端口号保持一致
}
}
3.在project目录下,创建log目录,并增加所有用户的写权限。
4.在project目录下,创建uwsgi的配置文件,wsgi.xml
<uwsgi>
<socket>127.0.0.1:9322</socket> #与上文nginx配置文件的端口号一致
<listen>80</listen>
<master>true</master>
<pidfile>/var/run/nginx.pid</pidfile> #ngix的id配置文件
<processes>8</processes>
<pythonpath>/srv/api/learner/</pythonpath> #project 的路径
<module>wsgi</module>
<profiler>true</profiler>
<memory-report>true</memory-report>
<enable-threads>true</enable-threads>
<wsgi-file>/srv/api/learner/learner/wsgi.py</wsgi-file> #django自动生成的wsgi.py路径
<logdate>true</logdate>
<limit-as>6048</limit-as>
<daemonize>/srv/api/learner/log/django.log</daemonize> #刚刚创建的log目录的路径
</uwsgi>
5.sudo /etc/init.d/nginx
sudo uwsgi -x xxxxxx/wsgi.xml
ps: 如果出现问题,先stop nginx或者kill nginx 和uwsgi
6.修改hosts
sudo vim hosts:
127.0.0.1 xxxx #与nginx的server_name 相同
7.浏览器访问xxx