【问题标题】:(upstream prematurely closed connection while reading response header from upstream) ..... && 502 bad gateway(从上游读取响应标头时,上游过早关闭连接)..... && 502 bad gateway
【发布时间】:2019-01-17 11:24:27
【问题描述】:

我在 /var/log/nginx 中收到此错误日志。当我运行该站点时,我在加载 30 秒后得到一个 502 错误网关。如果我删除一些(时间广泛的)代码行一切正常。我编辑了 nginx 配置文件,但我认为这不是问题。

我去了:/etc/nginx/sites-available/django,这是我的配置

upstream app_server {
    server unix:/home/django/gunicorn.socket fail_timeout=0;
     }

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

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name _;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/django_project/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/django_project/django_project/static;
    }

    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist- 
     packages/django/contrib/admin/static/admin/;
    }

    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_buffering off;
            proxy_read_timeout 110s;
            proxy_send_timeout 110s;
            proxy_pass http://app_server;
   }
}

我想我需要更改 gunicorn 配置文件中的超时时间,但我不知道那在哪里。没找到。

【问题讨论】:

    标签: nginx webserver gunicorn digital-ocean


    【解决方案1】:
    grep worker_processes /etc/nginx/nginx.conf
    worker_processes auto;
    

    将工作进程从“1”更改为“auto”

    在你的配置中使用它

    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1h;
    ssl_buffer_size 4k;
    

    【讨论】:

      猜你喜欢
      • 2018-06-11
      • 2015-08-08
      • 2022-11-27
      • 2018-09-21
      • 1970-01-01
      • 2019-12-09
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多