UWSGI + NGINX 502 Bad Gateway

时间:2015-02-27 17:33:09

标签: python ubuntu nginx uwsgi web.py

我有一个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实例。

1 个答案:

答案 0 :(得分:0)

我最近通过在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