I have nginx conf as follows:
server {
listen 127.0.0.1:8080;
server_name 127.0.0.1;
client_max_body_size 20m;
include /etc/nginx/conf.d/services/*.conf;
# redirect server error pages to the static page /50x.html
#
error_page 500 /500.json;
error_page 501 /501.json;
error_page 502 /502.json;
error_page 503 /503.json;
error_page 504 /504.json;
error_page 404 /404.json;
location = /500.json {
root /opt/lj/nginx;
}
location = /501.json {
root /opt/lj/nginx;
}
location = /502.json {
root /opt/lj/nginx;
}
location = /503.json {
root /opt/lj/nginx;
}
location = /504.json {
root /opt/lj/nginx;
}
location = /404.json {
root /opt/lj/nginx;
}
}
In the conf.d/services directory, I have a file with:
location /api/auth {proxy_pass http://127.0.0.1:8081;}
I have an upstream process listening on 8081 for requests. Almost accurately 2 our 3 times, the request gets redirected appropriately, but every third time, I get this error:
2014/10/09 03:03:52 [alert] 4572#0: *16 socket() failed (97: Address family not supported by protocol) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /api/auth/1.0/companies/1/clients HTTP/1.1", upstream: "http://[::1]:8081/api/auth/1.0/companies/1/clients", host: "localhost:8080"
I don't know how to make nginx only forward to the IPv4 address which the upstream understands.
Access logs: (Please note 1 out of 3 attempts results in 500 while the rest pass)
127.0.0.1 - portalAdmin [09/Oct/2014:02:56:37 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 500 107 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:02:57:38 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 200 2 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:02:57:39 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 200 2 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:02:57:41 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 500 107 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:03:03:44 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 200 2 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:03:03:45 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 200 2 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:03:03:46 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 500 107 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:03:03:50 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 200 2 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:03:03:51 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 200 2 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
127.0.0.1 - portalAdmin [09/Oct/2014:03:03:52 -0400] "GET /api/auth/1.0/companies/1/clients HTTP/1.1" 500 107 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36" "98.207.234.244"
Any help would be greatly appreciated! Thanks.
Maybe you have "localhost" instead of "127.0.0.1" somewhere in your config. You could specify a resolver and set ipv6 to off.
resolver 8.8.8.8 4.2.2.2 ipv6=off;
If your webservice on port 8081 is on nginx too, then enabling IPv6 for this could solve the problem.
server {
listen 8081;
listen [::]:8081;
....
}
I had the same issue. Changing the Ipv6only=on; ==> to ==> Ipv6only=off; didn't work for me. When I removed the "Ipv6only=off/on" completely - it started working like charm!
Try to remove to remove it completely and reloading nginx service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With