繁体   English   中英

UWSGI + NGINX 502错误网关

[英]UWSGI + NGINX 502 Bad Gateway

我有一个Web.py应用程序,想将其投入生产。 根据Web.py社区的建议,我决定为此使用uWSGI和Nginx。

我的应用程序将Memcached用于会话存储,将MySQL用于其他存储任务。 该应用程序可以在我的MacBook上正常运行。 我之前配置了uWSGI + Nginx设置,效果很好。 但是,当我尝试访问Ubuntu服务器上的索引页面时,我会收到502 Bad Gateway。 但是:进入另一个页面时,我会收到所有想要的内容。 通常,该应用程序在Ubuntu环境中运行良好,因为我通过键入python app.py 8080对其进行了测试。 我能够输入page.tld:8080 /并接收所有内容。

我的uWSGI配置:

[uwsgi]
gid = www-data
uid = www-data
vhost = true
plugins = python
logdate
#socket = /tmp/uwsgi_vhosts.sock
socket = 127.0.0.1:3031
master = true
processes = 1
harakiri = 120
limit-as = 128
memory-report
no-orphans

Nginx配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    # Make site accessible from http://localhost/
    server_name page.tld;

    location / {
            include uwsgi_params;


         uwsgi_pass 127.0.0.1:3031;

    # This is the absolute path to the folder containing your application
            uwsgi_param UWSGI_CHDIR /var/www/page.tld/apps;

    # This is actually not necessary for our simple application,
    # but you may need this in future
            uwsgi_param UWSGI_PYHOME /var/www/page.tld/apps;

    # This is the name of your application file, minus the '.py' extension
            uwsgi_param UWSGI_SCRIPT test;
  }

我一直在uWSGI的vhosts.log中获得以下代码:

libgcc_s.so.1 must be installed for pthread_cancel to work
 - DAMN ! worker 1 (pid: 1281) died, killed by signal 6 :( trying respawn ...
 - Respawned uWSGI worker 1 (new pid: 1330)
Please let me know if you need to see other parts of the configuration.

这些行在nginx的error.log中:

[error] 1233#0: *1 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: page.tld, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "page.tld"

让我知道是否需要其他日志来解决此问题。

更新:当我想访问必须从MySQL数据库加载内容的页面时,似乎得到502 Bad Gateway。 但是由于它在没有uWSGI和NGINX的情况下可以正常工作,我想nginx在尝试从数据库中加载东西时会出于某种原因杀死uwsgi实例。

我最近通过在uwsgi中设置更高的内存限制来解决此问题。 您将需要重新启动uwsgi。 我在启动时正在运行uwsgi皇帝。 因此,就我而言,我重新启动了。

[uwsgi]
...
limit-as = 512

系统:

  • Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64)
  • mysqlclient==1.3.6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM