使用UWSGI和NGINX提供金字塔应用程序

使用UWSGI和NGINX提供金字塔应用程序,nginx,pyramid,reverse-proxy,uwsgi,Nginx,Pyramid,Reverse Proxy,Uwsgi,我对NGINX、uWSGI和Pyramid都是新手,我正试图通过uWSGI使用NGINX作为反向代理来为Pyramid应用程序提供服务。我现在真的很困惑,希望有人能提出一些建议来解决这个问题。如果你能解释一下可能发生的事情,那也会很有帮助,因为我的理解非常有限 目前,当我访问反向代理URL时,我从uWSGI收到一个“内部服务器错误”。在uWSGI错误日志中,我得到错误: --- no python application found, check your startup logs for er

我对NGINX、uWSGI和Pyramid都是新手,我正试图通过uWSGI使用NGINX作为反向代理来为Pyramid应用程序提供服务。我现在真的很困惑,希望有人能提出一些建议来解决这个问题。如果你能解释一下可能发生的事情,那也会很有帮助,因为我的理解非常有限

目前,当我访问反向代理URL时,我从uWSGI收到一个“内部服务器错误”。在uWSGI错误日志中,我得到错误:

--- no python application found, check your startup logs for errors ---
当我单独通过uWSGI服务时,该应用程序运行良好,使用pserve启动。我可以从虚拟信封中启动它,如下所示:

bin/pserve my-app/uwsgi.ini
[app:main]
use = egg:myapp
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid_debugtoolbar
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

[loggers]
keys = root, musiccircle

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = ERROR
handlers = console
[logger_musiccircle]
level = ERROR
handlers =
qualname = musiccircle

[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

[uwsgi]
socket = unix://home/usr/env/myapp/myapp.sock
master = true

processes = 48
cpu-affinity = 12

harakiri = 60
post-buffering = 8192
buffer-size = 65535

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

listen = 32767

reload-on-as = 512
reload-on-rss = 192
limit-as = 1024
no-orphans = true
reload-mercy = 8
log-slow = true

virtualenv = /home/usr/env
但是当我启动nginx并访问代理地址时,我得到了内部服务器错误

我在uwsgi.ini中的设置如下:

bin/pserve my-app/uwsgi.ini
[app:main]
use = egg:myapp
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid_debugtoolbar
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

[loggers]
keys = root, musiccircle

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = ERROR
handlers = console
[logger_musiccircle]
level = ERROR
handlers =
qualname = musiccircle

[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

[uwsgi]
socket = unix://home/usr/env/myapp/myapp.sock
master = true

processes = 48
cpu-affinity = 12

harakiri = 60
post-buffering = 8192
buffer-size = 65535

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

listen = 32767

reload-on-as = 512
reload-on-rss = 192
limit-as = 1024
no-orphans = true
reload-mercy = 8
log-slow = true

virtualenv = /home/usr/env
在nginx中相应的myapp.conf文件中,我有以下内容:

upstream myapp {
    server 127.0.0.1:6543;
}

server {
    listen          8080;
    server_name myapp.local www.myapp.local;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/usr/env/myapp;
    }
    access_log      /var/log/nginx/access.log;
    error_log       /var/log/nginx/error.log;

    charset         utf-8;
    location / {
        include         uwsgi_params;
        uwsgi_pass      unix://home/usr/env/myapp/myapp.sock;
    }
}
如果你还需要看什么,请告诉我。如您所见,Nginx被配置为在端口8080(确实如此)服务,而金字塔应用程序由uWSGI提供到端口6543(确实如此)


提前感谢。

金字塔项目似乎打算安装(
setup.py
),然后使用
.ini
配置文件和
pserve
运行。然后,Pserve在运行时将这些配置文件详细信息作为
**设置
传递给您的Pyramid应用程序

这与未安装且通常没有配置文件的烧瓶不同。这种Flask应用程序可以根据需要由uWSGI运行,所有运行时配置都由uWSGI或环境变量处理


由于Pyramid通常在运行时需要一个配置文件,并且在使用配置文件(即
production.ini
)时依赖pserve提供它们,因此我认为您必须运行
uwsgi--ini paste production.ini
(或者如果使用pypypypy运行,
uwsgi--pypypy paste production.ini
)(感谢@Sorrel)

据我所知,您的配置文件是针对Pyramid
pserve
的,而不是针对
uwsgi
。在nginx.conf中,尝试将服务器127.0.0.1:6543更改为服务器0.0.0.0:6543。在nginx文件中,uwsgi_pass指令应该是uwsgi_passunix:///home/usr/env/myapp/myapp.sock; (3个斜杠)。在您的uwsgi.ini文件中,这些行使用=egg:waiteress#main,host=0.0.0,port=6543。在[uwsgi]部分中,指定套接字路径时不必添加unix://命令。为我做的另一件事是为套接字添加适当的权限。这是我的wsgi部分的配置。我从env/bin/uwsgi开始——ini-paste-uwsgi.ini-mikko-Ohtamaa,你是对的……我的应用程序是通过paster/pserve与服务员一起提供的,而不是uwsgi。因此我决定,为什么不修改我的nginx配置文件,继续为女服务员服务呢?这就是我所做的,克鲁克西,谢谢,你是对的,我需要修改我的.ini文件,以便2个主机IP匹配。它现在正在使用waiteress+nginx配置,尽管我在使用Chrome访问网站时遇到了问题(不过这是另一个问题!)。网络迷,谢谢你的建议,我也会尝试这个选项。是的,我认为运行Nginx+pserve是可能的,尽管大多数人似乎更喜欢uwsgi。