使用Nginx + Waitress部署Pyramid应用程序

时间:2014-03-09 16:43:06

标签: nginx pyramid

我尝试在VPS服务器上部署我的应用程序,我已经有两个Web应用程序,在同一个IP地址上,但是服务于Apache并且实际上运行在PHP上。所以,我想做的是使用Nginx和Pserve在相同的IP上运行Pyramid应用程序(我不确定Waitress的内容是什么,但我的配置文件中有几行)。

我的 production.ini 配置:

[app:main]
use = egg:gsoft

jinja2.directories =
    gsoft:core/templates
    gsoft:admin/templates
    gsoft:admin/cat/templates
    gsoft:admin/post/templates
    gsoft:admin/page/templates
    gsoft:admin/settings/templates

pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_tm

mongo_uri = mongodb://localhost:27017/gsoft

[server:main]
use = egg:waitress#main
host = gsoft-domain.com
port = 5000

[loggers]
keys = root, gsoft

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console

[logger_gsoft]
level = WARN
handlers =
qualname = gsoft

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

和Nginx域配置, /etc/nginx/sites-available/gsoft-domain.com

upstream gsoft-domain.com {
    server 127.0.0.1:5000;
    server 127.0.0.1:5001;
}

server {

    server_name  gsoft-domain.com;
    charset     utf-8

    access_log  /root/gsoft-domain.com/logs/access.log;

    location / {
        proxy_set_header        Host $http_host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;

        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   60s;
        proxy_send_timeout      90s;
        proxy_read_timeout      90s;
        proxy_buffering         off;
        proxy_temp_file_write_size 64k;
        proxy_pass              http://gsoft-domain.com;
        proxy_redirect          off;
    }
}

我实际上并不了解这一切,它来自文档中的官方金字塔食谱。

在nginx配置文件中 /etc/nginx/nginx.conf 我没有什么特别的,所以我意识到不要在这里发布它,因为我没有在nginx之后更改那里的行已安装。

当我尝试使用命令运行pserve时:

root@gsoft:~/gsoft# pserve production.ini --reload
Starting subprocess with file monitor
Starting server in PID 19573.
serving on http://gsoft-domain:5000

当然使用已解析的IP地址而不是gsoft-domain。一切运行良好,但只在 5000 端口!当我试图打开没有指定端口的网站时,我看到我的第一个网站,由Apache服务=)那么我怎么能配置所有这些纠结的配置,使我的应用程序默认在 80 端口上工作。我知道我可以购买另一个静态IP地址并使用80端口重新配置以上配置,但我希望有一种方法可以在同一个IP上运行多个Pyramid应用程序。

2 个答案:

答案 0 :(得分:0)

如果您安装Flup,那么您也可以配置nginx而无需创建代理并将pserve生成为FastCGI进程:

<强> production.ini

[server:main]
use = egg:Flup#fcgi_thread
host = 0.0.0.0
port = 5000

<强>命令

 prj-env/bin/pserve --daemon --pid-file=$PID_FILE --log-file=$LOG_FILE --user=$USER --group=$GROUP production.ini start

<强> Nginx的

server {

server_name  gsoft-domain.com;
charset     utf-8

access_log  /root/gsoft-domain.com/logs/access.log;

location / {

fastcgi_pass   gsoft-domain;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}

upstream gsoft-domain {
   server 127.0.0.1:5000;

} 

答案 1 :(得分:-1)

不是将应用程序作为单独的进程运行并使用nginx代理它,您可以使用apache的mod_wsgi模块:

http://modwsgi.readthedocs.org/en/latest/configuration-guides/running-a-basic-application.html

您可以按照django指南使用mod_wsgi部署金字塔应用。区别仅在于django.wsgi文件。将其命名为myapp.wsgi并使用pyramid.paster.loadapp加载应用程序:

from pyramid.paster import loadapp
from logging.config import fileConfig

fileConfig("/absolute/path/to/production.ini")
application = loadapp("config:/absolute/path/to/production.ini")

https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/