NGINX error: "Invalid port in upstream" when using proxy_pass with IPv6 -
i have been unable find explanation nginx error on nginx version: nginx/1.9.14.
this nginx.conf attempts forward client request webserver port 442 port 9442.
when using ipv4 client , server address works fine , webserver request forwarded 9442. when using ipv6 address client , server address following error occurs:
2017/08/21 19:05:56 [error] 6694#0: *5 invalid port in upstream "2000::157:9442/", client: 2000::158, server: , request: "get / http/1.1", host: "[2000::157]:442" nginx.conf:
http { server { listen 442 ssl; # ipv4 support listen [::]:442 ssl; # ipv6 support ssl_certificate /etc/ssl/active.crt; ssl_certificate_key /etc/ssl/active.key; ssl on; ssl_session_cache builtin:1000 shared:ssl:10m; ssl_protocols tlsv1 tlsv1.1 tlsv1.2; ssl_prefer_server_ciphers on; location / { proxy_pass https://$server_addr:9442$request_uri; } } } what "invalid port in upstream" mean exactly?
note ipv6 addresses in example made sake of example , on private network not seen outside world.
so issue because of ip formats. $sever_addr 127.0.0.1 or local ip ipv4. while ipv6 ::1 or 2000::157 1 got. or have : in address.
now when proxy_pass using $server_addr, become either http://127.0.0.1:9442 or http://::1:9442. ipv4 1 valid ipv6 1 not valid. needs http://[::1]:9442. fix easy, use map in our http block.
map $server_addr $proxy_pass_ip { default "$server_addr"; ~.*:.* "[$server_addr]"; } and change our location block like
location / { proxy_pass https://$proxy_pass_ip:9442$request_uri; } wiki
Comments
Post a Comment