uwsgi yourfile.ini # 配置文件
[uwsgi]
http = 127.0.0.1:3106
socket = 127.0.0.1:3006
chdir = /www/studentapitest/zhishidian
pythonpath = /www/studentapitest/
env = DJANGO_SETTINGS_MODULE=zhishidian.linux_settings
module = django.core.handlers.wsgi:WSGIHandler()
workers = 4
max-request = 2000
master = true
harakiri = 30
pidfile = /www/config/studentapitest.tbkt.cn.pid
touch-reload = /www/config/studentapitest.tbkt.cn.reload.txt
daemonize = /www/logs/studentapitest.tbkt.cn.uwsgi.log
加入http參數后就可以以http形式訪問,配置好並啟動uwsgi服務后,在瀏覽器中輸入http://127.0.0.1:3106就可以直接訪問了,這樣配置的優點是可以用程序直接訪問,3006和3106兩個端口是在一個進程里面運行
如下python代碼片段
import urllib2
res = urllib2.urlopen("http://127.0.0.1:3106/login/")
print res.read()
nginx 則可以socket形式訪問
location / {
uwsgi_pass 127.0.0.1:3106;
include uwsgi_params;
}
更多用法參考官方文檔
http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html#deploying-django
http://uwsgi-docs.readthedocs.org/en/latest/HTTP.html