5

大多数可用的教程都展示了如何使用上游 HTTP 服务器(如 NGINX)设置 uWSGI。但是单独的uWSGI可以很好地充当路由器/代理/负载平衡器 - 参考这个 对于我的项目,我现在不想设置 NGINX,所以我开始探索通过 uWSGI 提供网页的选项。此处的答案显示了如何使用Pyramid进行设置。

4

2 回答 2

11

我正在使用 pyramid_mongodb 脚手架,我对其进行了修改以使其在 python3 上工作。有关详细信息,请参见此处。假设我们有一个 Pyramid 项目(使用 创建pcreate -s pyramid_mongodb MyProject)。以下是 development/production.ini 中所需的 uWSGI 配置

[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

server此外,由于我们使用的是 uWSGI,我们可以从 ini中注释掉部分

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

要运行服务器,请使用 uwsgi --ini-paste development.ini

于 2013-05-03T04:25:12.117 回答
2

更容易!根本不需要修改“development.ini”文件。在“开发”和“生产”ini 文件所在的 App 文件夹中创建一个名为“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 的配置非常简单:

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. 使用“/path/to/usr/sbin/nginx -s reload”重启 nginx
  2. 启动 uwsgi 进程 -> 更改为“cd /usr/local/uwsgi-2.0.9” -> ./uwsgi -ini /var/www/myapp.conf
于 2015-05-14T10:15:18.287 回答