Nginx:110:从上游读取响应头时,连接超时

时间:2019-02-26 19:53:29

标签: nginx

我已经阅读了其他相关文章,并实现了最佳答案,仍然出现此错误。

我正在使用Nginxsupervisor(由于daphneDjango Channels)运行Django应用。

我转到域名时得到504 Gateway Time-out

我已经阅读了nginx错误日志的输出:

2019/02/26 19:34:52 [error] 22668#22668: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xx.xx.xxx.14, server: myapp.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.myapp.com"

我尝试添加超时设置:

 # time out settings
        proxy_connect_timeout 159s;
        proxy_send_timeout   600;
        proxy_read_timeout   600;
        proxy_buffer_size    64k;
        proxy_buffers     16 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
        proxy_pass_header Set-Cookie;
        proxy_redirect     off;
        proxy_hide_header  Vary;
        proxy_set_header   Accept-Encoding '';

我尝试添加

        proxy_http_version 1.1;
        proxy_set_header Connection "";

使用

添加文件(/etc/nginx/conf.d/timeout.conf
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;

似乎没有任何效果。我是一个初学者,所以如果我在这里想念任何东西,请告诉我!

配置文件/ etc / nginx / sites-enabled / myapp

upstream myapp {
    server 127.0.0.1:8000;
}

server {
    server_name myapp.com www.myapp.com;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        try_files $uri @proxy_to_app;
    }

    location /static/ {
        root /home/me/myapp/src/myapp;
    }

    location /media/  {
        root /home/me/myapp/src/myapp;
        include /etc/nginx/mime.types;
    }

    location @proxy_to_app {
        proxy_pass http://myapp;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect 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_set_header X-Forwarded-Host $server_name;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}


server {
    if ($host = www.myapp.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = myapp.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name myapp.com www.myapp.com;
    return 404; # managed by Certbot

0 个答案:

没有答案