简体   繁体   English

Nginx 502错误网关错误时带有gunicorn的烧瓶

[英]Flask with gunicorn on nginx 502 bad gateway error

After some ubuntu 16.04 upgrades and app code modifications, my Flask on gunicorn and nginx website which previously was working is now giving a 502 bad gateway error. 经过一些ubuntu 16.04升级和应用程序代码修改后,以前在gunicorn和nginx网站上运行的Flask现在出现502错误的网关错误。

myapp.conf: myapp.conf:

upstream app_server_wsgiapp {
  server localhost:8000 fail_timeout=0;
}

server {
  listen 80;
  server_name www.myserver.com;

  access_log   /var/log/nginx/www.myapp.access.log;
  error_log   /var/log/nginx/www.myapp.error.log info;
  keepalive_timeout    5;

  location /static {
    autoindex on;
    alias /myapp/static;
  }

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    if (!-f $request_filename) {
      proxy_pass http://app_server_wsgiapp;
      break; 
    }
    client_max_body_size 2097152;
    #to get around upstream sent too big header while reading response header from upstream error
    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
  }

  # this section allows Nginx to reverse proxy for websockets
  location /socket.io {
    proxy_pass http://app_server_wsgiapp/socket.io;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  } 
}

/var/log/nginx/myapp.error.log /var/log/nginx/myapp.error.log

2017/06/11 06:42:52 [error] 31054#31054: *1 connect() failed (111: Connection refused) while connecting to upstream, client: clientip, server: www.myserver.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.myapp.com"

From my apps log file I note that Flask gets part of the way through starting up, then restarts in a continuous fail/restart loop. 从我的应用程序日志文件中,我注意到Flask是启动过程的一部分,然后以连续的失败/重新启动循环重新启动。

Any ideas how I can go about debugging what could be causing this issue? 关于如何调试可能导致此问题的任何想法?

Looks like the problem is caused by flask app running error. 看来问题是由flask应用运行错误引起的。 Could you please try to run the app in interactive way? 您可以尝试以交互方式运行该应用程序吗? With same params and environment settings in daemon way and check whether the service can be started correctly? 在守护程序方式下使用相同的参数和环境设置,并检查服务是否可以正确启动?

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

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