Nginx反向代理504网关超时仅发生在浏览器访问中

时间:2018-03-29 01:38:28

标签: nginx kubernetes-ingress

我使用Nginx作为反向代理,当我从浏览器(Chrome,Firefox)访问网址时,它将显示504网关超时。但是,当我使用curlwget访问网址时,它可以正常工作。这真是一个奇怪的问题,任何人都可以给我一些帮助吗?

以下是我的配置:https://pastebin.com/fZHEtRGa

上游配置为:

upstream default-nginx-z-80 {
    # Load balance algorithm; empty for round robin, which is the default

    least_conn;

    keepalive 32;

    server 10.1.228.195:80 max_fails=0 fail_timeout=0;

}

服务器配置

server {
    server_name z-ingress.mixhub.cn ;

    listen 80;

    listen [::]:80;

    set $proxy_upstream_name "-";

    location / {
        port_in_redirect off;

        set $proxy_upstream_name "default-nginx-z-80";

        set $namespace      "default";
        set $ingress_name   "nginx-z";
        set $service_name   "";

        client_max_body_size                    "1m";

        proxy_set_header Host                   $best_http_host;

        # Pass the extracted client certificate to the backend

        proxy_set_header ssl-client-cert        "";
        proxy_set_header ssl-client-verify      "";
        proxy_set_header ssl-client-dn          "";

        # Allow websocket connections
        proxy_set_header                        Upgrade           $http_upgrade;

        proxy_set_header                        Connection        "";

        proxy_set_header X-Real-IP              $the_real_ip;

        proxy_set_header X-Forwarded-For        $the_real_ip;

        proxy_set_header X-Forwarded-Host       $best_http_host;
        proxy_set_header X-Forwarded-Port       $pass_port;
        proxy_set_header X-Forwarded-Proto      $pass_access_scheme;
        proxy_set_header X-Original-URI         $request_uri;
        proxy_set_header X-Scheme               $pass_access_scheme;

        # Pass the original X-Forwarded-For
        proxy_set_header X-Original-Forwarded-For $http_x_forwarded_for;

        # mitigate HTTPoxy Vulnerability
        # https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
        proxy_set_header Proxy                  "";

        # Custom headers to proxied server

        proxy_connect_timeout                   5s;
        proxy_send_timeout                      60s;
        proxy_read_timeout                      60s;

        proxy_redirect                          off;

        proxy_buffering                         off;
        proxy_buffer_size                       "4k";
        proxy_buffers                           4 "4k";
        proxy_request_buffering                 "on";

        proxy_http_version                      1.1;

        proxy_cookie_domain                     off;
        proxy_cookie_path                       off;

        # In case of errors try the next upstream server before returning an error
        proxy_next_upstream                     error timeout invalid_header http_502 http_503 http_504;

        proxy_pass http://default-nginx-z-80;

    }

}

0 个答案:

没有答案