UWSGI + NGINX 502 错误网关 [英] UWSGI + NGINX 502 Bad Gateway

查看:83
本文介绍了UWSGI + NGINX 502 错误网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got a Web.py app and wanted to push it into production. As recommended by the Web.py Community I decided to use uWSGI and Nginx for this.

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

My App uses Memcached for Session Storing and MySQL for other storing tasks. The app works fine on my MacBook. I configured the uWSGI + Nginx setup previously which worked fine. But know I receive a 502 Bad Gateway when I try to access the Index Page on my Ubuntu Server. BUT: when entering another page I receive all the content I wanted. In general the app works fine in the Ubuntu environment, as I tested it by typing python app.py 8080. I was able to enter the page.tld:8080/ and receive all content.

我的 uWSGI 配置:

My uWSGI config:

[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 中不断收到这些行:

I keep getting this lines in the vhosts.log of uWSGI:

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 中的这些行:

And these lines in the error.log of nginx:

[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"

如果需要任何其他日志来解决这个问题,请告诉我.

Let me know if any other logs are needed to solve this.

更新:当我想访问必须从 MySQL 数据库加载内容的页面时,我似乎收到了 502 Bad Gateway.但是因为它在没有 uWSGI & 的情况下工作NGINX 我猜 nginx 在尝试从数据库加载内容时出于某种原因杀死了 uwsgi 实例.

Update: It seems that I get 502 Bad Gateway, when I want to access a page that has to load things from the MySQL Database. But as it is working without uWSGI & NGINX I guess that nginx kills the uwsgi instance for some reason when it tries to load things from the Database.

推荐答案

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

I recently fixed this problem by setting a higher memory limit within the uwsgi. You will need to restart the uwsgi. I am running uwsgi emperor at start up. So, in my case I rebooted.

[uwsgi]
...
limit-as = 512

系统:

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

这篇关于UWSGI + NGINX 502 错误网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆