Disable IPv6 in upstream servers for NginX during proxy_pass

Viewed 333

Currently have Nginx running on the same machine as the rest of my servers, none of which are running IPv6. Relatively frequently, I get hangups when loading content while testing and I find error messages in the error.log file.

My current config:


http {
    include       mime.types;
    sendfile      on;
    tcp_nopush    on;
    tcp_nodelay   on;
    server_tokens off;
    resolver      1.1.1.1 ipv6=off;

    #keepalive_timeout  0;
    keepalive_timeout  60s;

    upstream master_process {
        localhost:40088;
    }
    upstream http_worker {
        hash $remote_addr consistent;
        localhost:40089;
        localhost:40090;
        localhost:40091;
        localhost:40092;
    }

    #http server
    server {
        listen 88;

        location / {
            lingering_close     on;
            lingering_time      15s;
            lingering_timeout   2s;
            proxy_pass          http://http_worker;
            proxy_http_version  1.1;
            proxy_set_header    Connection          "Upgrade";
            proxy_set_header    Host                $host;
            proxy_set_header    Upgrade             $http_upgrade;
            proxy_set_header    X-Real-IP           $remote_addr;
        }

        location ~ ^/(Main|Monitor|Chart|chartfeed|getchartdata()|Live|Log$) {
            proxy_pass          http://master_process;
            proxy_http_version  1.1;
            proxy_set_header    Connection          "Upgrade";
            proxy_set_header    Host                $host;
            proxy_set_header    Upgrade             $http_upgrade;
            proxy_set_header    X-Real-IP           $remote_addr;
        }
        location ~.*.(gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|txt|js|css|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|htm)$ {
            proxy_pass          http://master_process;
            gzip_static         on;
            expires             7d;
        }
    }

}

The errors I am currently receiving:

2022/01/28 11:42:27 [error] 23732#17404: *1 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /Main?_SID=1*479985359 HTTP/1.1", upstream: "http://[::1]:40088/Main?_SID=1*479985359", host: "localhost:88", referrer: "http://localhost:88/login()"
2022/01/28 11:42:52 [error] 23732#17404: *1 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /Main?_SID=1*479985359 HTTP/1.1", upstream: "http://[::1]:40088/Main?_SID=1*479985359", host: "localhost:88", referrer: "http://localhost:88/login()"

Note that I have specified a resolver in the http section so that it can be made global. I have also tried moving that resolver into the server and location sections to no avail. I have also tried adding {server {listen 88 default_server; listen [::]:88 ipv6only=on; ...}...} which also didn't solve this issue as others have suggested after a quick search online.

Any help would be greatly appreciated!

0 Answers
Related