首页 > 解决方案 > AWS ALB 随机 504 网关超时

问题描述

这是我的设置:

ALB(侦听端口 443)->NGINX(侦听端口 444,因为其他东西在 $host 的 EC2 proxy_pass 上使用 443)

我的问题是我只会在每次通过 ALB 使用 HTML 时提取 HTML。我知道这不是我的 Nginx 配置,因为如果我这样做了

curl --location -vvv -k 'https://$EC2_IP:444' -H 'Host: $FORWARD_HOST.LOCAL'

我每次都拉 HTML,即使我做了一个 for 循环并且真的是垃圾邮件。有什么想法要解决,或者以前有没有其他人遇到过这个问题?

更新:经过一番挖掘,看起来 request_processing_time 可能是罪魁祸首:

如果负载均衡器无法将请求分派到目标,则此值设置为 -1。如果目标在空闲超时之前关闭连接或客户端发送格式错误的请求,则可能会发生这种情况。

修改我的 nginx.conf 后会报告。我已经调整了我能想到的一切都不起作用:/

nginx.conf
user nginx;

worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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/nginx/access.log  main;

    resolver 127.0.0.1;
    resolver_timeout 60s;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   62s;
    types_hash_max_size 2048;

    # 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;

    # Settings for a TLS enabled server.

    server {
        listen       444 ssl default_server;
        listen       [::]:444 ssl default_server;
        server_name  _;

        ssl_password_file /etc/nginx/my_certs/password_file;
        ssl_certificate /etc/nginx/my_certs/my.pem;
        ssl_certificate_key /etc/nginx/my_certs/my.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  1m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location ^~ /proxycheck {
            return 200 'available';
            add_header Content-Type text/plain;
        }

        location / {
            set $upstream_endpoint https://$http_host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_pass $upstream_endpoint;
        }

    }

}

/etc/nginx/conf.d/timeout.conf

proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;

标签: amazon-web-servicesnginxaws-application-load-balancer

解决方案


推荐阅读