首页 文章

带有gunicorn的烧瓶nginx 502坏网关错误

提问于
浏览 16
1

在一些ubuntu 16.04升级和应用程序代码修改之后,我在之前工作的gunicorn和nginx网站上的Flask现在给出了502错误的网关错误 .

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

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"

从我的应用程序日志文件中我注意到Flask通过启动获得了一部分,然后在连续的失败/重启循环中重新启动 .

任何想法如何我可以调试可能导致此问题的原因?

1 回答

  • 2

    看起来问题是由于应用程序运行错误引起的 . 你可以尝试以交互方式运行应用程序吗?在守护进程中使用相同的参数和环境设置并检查服务是否可以正确启动?

相关问题