带有 AWS NLB 和 Gunicorn 的 NGINX HTTP 499 _ Django

问题描述

我正在运行 Nginx + Gunicorn 设置来为来自 AWS EC2s 的 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;
            }
        }      
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...