2013-05-03 59 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

相關問題