nginx + uwsgi + django 部署
环境: os UBUNTU12
nginx 1.2.4
python 2.7
django 1.4
uwsgi 1.4.2
1 安装Nginx uwsgi
pip install uwsgi
2 配置Nginx与uwsgi
nginx配置:
/etc/nginx/nginx.conf 是nginx的主配置文件
在 /etc/nginx/sites-enabled 创建新的文件,名称随便.在此用test.conf
test.conf
server {
listen 80;
server_name 10.2.8.111;
location / {
root /home/tc/trunk/ui;
uwsgi_pass 127.0.0.1:8888;
include uwsgi_params;
access_log off; }
}
uwsgi配置:
在django的project目录下面创建wsgi.py以及wsgi.xml
wsgi.py:
import os,sys
if not os.path.dirname(__file__) in sys.path[:1]:
sys.path.insert(0, os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()
wsgi.xml
127.0.0.1:8888
路径
..
wsgi
3 启动uwsgi 与nginx
uwsgi -x wsgi.xml
sudo /etc/init.d/nginx start
问题:
每次修改django代码之后都需要重启uwsgi,解决方法是在wsgi.py中添加如下代码:
import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload
@timer(3)
def change_code_gracefull_reload(sig):
if autoreload.code_changed():
uwsgi.reload()
或者在启动uwsgi的时候直接加 --touch-reload /tmp/.ops-reload 参数
阅读(1151) | 评论(0) | 转发(0) |