0

我正在运行 NGINX + Gunicorn 设置以从 AWS EC2 为我的 Django 应用程序提供服务,该应用程序在前面有一个网络负载均衡器。最近我从我的 NGINX 收到了很多 HTTP 499,它们都是连续的,而不是一次性的。

AWS 网络负载均衡器具有 350 秒的固定空闲超时,我相信无法修改。我所有的 NGINX 超时都设置为 600。

这还有什么原因?

下面是我的 NGINX 配置

user <someuser>;
worker_processes auto;
error_log /var/log/<somedir>/nginx_error_main.log;
pid /var/run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/<somedir>/nginx_access_main.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   600;
    types_hash_max_size 2048;

    proxy_ignore_client_abort on;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    # Enable upgrading of connection (and websocket proxying) depending on the
    # presence of the upgrade field in the client request header
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    # Create an upstream alias to where we've set daphne to bind to
    upstream django_app_server {
        server unix:/home/<somedir>/gunicorn.sock fail_timeout=0;
    }

    server {
        listen   8001 default;
        listen [::]:8001;
        server_name _;

        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;

        client_max_body_size 4G;

        access_log /var/log/<somedir>/nginx-access.log;
        error_log /var/log/<somedir>/nginx-error.log;

        location /static/ {
            alias   /home/<somedir>/static/;
        }

        location /media/ {
            alias   /home/<somedir>/media/;
        }

        location / {
            # an HTTP header important enough to have its own Wikipedia entry:
            #   http://en.wikipedia.org/wiki/X-Forwarded-For
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            # enable this if and only if you use HTTPS, this helps Rack
            # set the proper protocol for doing redirects:
            # proxy_set_header X-Forwarded-Proto https;

            # pass the Host: header from the client right along so redirects
            # can be set properly within the Rack application
            proxy_set_header Host $http_host;

            # we don't want nginx trying to do something clever with
            # redirects, we set the Host: header above already.
            proxy_redirect off;

            # set "proxy_buffering off" *only* for Rainbows! when doing
            # Comet/long-poll stuff.  It's also safe to set if you're
            # using only serving fast clients with Unicorn + nginx.
            # Otherwise you _want_ nginx to buffer responses to slow
            # clients, really.
            # proxy_buffering off;

            # Try to serve static files from nginx, no point in making an
            # *application* server like Unicorn/Rainbows! serve static files.
            if (!-f $request_filename) {
                proxy_pass http://django_app_server;
                break;
            }
        }      
    }
}
4

0 回答 0