以http形式启动uwsgi服务

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

原文地址:https://www.cnblogs.com/weiok/p/5364948.html