2013-05-03 61 views
5

大多数可用教程显示如何使用上游HTTP服务器(如NGINX)设置uWSGI。但是uWSGI单独可以作为路由器/代理/负载平衡器的精美行为 - 请参阅this 对于我的项目,此刻我不想设置NGINX,所以我开始探索通过uWSGI提供网页的选项。这里的答案显示了如何使用Pyramid进行设置。将uWSGI设置为带有金字塔的网络服务器(无NGINX)

回答

10

我正在使用pyramid_mongodb脚手架,我已修改它以使其在python3上工作。有关详细信息,请参阅here。 假设我们有一个金字塔项目(使用pcreate -s pyramid_mongodb MyProject创建)。 以下是开发/ production.ini

[uwsgi] 
http = 0.0.0.0:8080 
#http-to /tmp/uwsgi.sock - use this for standalone mode 
#socket = :9050 
master = true 

processes = 2 

harakiri = 60 
harakiri-verbose = true 
limit-post = 65536 
post-buffering = 8192 

daemonize = ./uwsgi.log 
pidfile = ./orange_uwsgi.pid 

listen = 128 

max-requests = 1000 

reload-on-as = 128 
reload-on-rss = 96 
no-orphans = true 

#logto= <log file> 
log-slow = true 

virtualenv = <path to virtual environment> 

#file = /path/to/pyramid.wsgi 
#callable = application 

need-app = true 

也需要uWSGI配置,因为我们使用uWSGI我们可以注释掉从INI

#[server:main] 
#use = egg:waitress#main 
#host = 0.0.0.0 
#port = 6544 

server部分运行服务器使用 uwsgi --ini-paste development.ini

2

更容易!不需要修改所有“development.ini”文件。 在应用中创建文件夹,您的“发展”和“生产”的ini文件所在,一个名为“wsgi.app”有以下内容的文件:

from pyramid.paster import get_app,setup_logging 

ini_path = '/pathto/myapp/development.ini' 
setup_logging(ini_path) 
application = get_app(ini_path,'main') 

创建让我们说“myapp.conf”与它的内容:

[uwsgi] 
socket = 127.0.0.1:3053 
uid = daemon 
gid = daemon 

venv = /pathto/myenv 
project_dir = /pathto/myapp 
chdir = %(project_dir) 
master = true 
plugins = plugins/python/python 

check-static = %(project_dir) 
static-skip-ext = .py 
static-skip-ext = .pyc 
static-skip-ext = .inc 
static-skip-ext = .tpl 

pidfile2 = /var/run/uwsgi/myinfo.pid 
disable-logging = true 
processes = 8 
cheaper = 2 

enable-threads = true 
offload-threads = N 
py-autoreload = 1 
wsgi-file = /pathto/myapp/wsgi.py 

和NGINX configuation很简单:用

server { 
listen [xxxx:xxxx:xxxx:xxx:xxxx:xxxx]:80; #for IPv6 
listen xxx.xxx.xxx.xxx:80; #for IPv4 

server_name myapp.domain.com; 

location/{ 
    try_files $uri @uwsgi; 
} 

location @uwsgi { 
     include uwsgi_params; 
     uwsgi_pass 127.0.0.1:3053; 
    } 
} 
  1. 重启nginx的“/路径/到/ usr/sbin目录/ nginx的-s刷新”
  2. 启动uwsgi过程 - >更改为 “CD /usr/local/uwsgi-2.0.9” - > ./uwsgi -ini /var/www/myapp.conf
+0

本例中的NGINX部分仅为(可选)。但在这一点上,应用程序应该能够在http://127.0.0.1:3053上收听请求 – SmileMZ 2015-05-14 10:24:18

相关问题