Opened 6 years ago

Closed 6 years ago

#1526 closed defect (duplicate)

Absolute redirect auto-triggered by location does not include port from Host header

Reported by: powerman@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.13.x
Keywords: Cc:
uname -a: Linux home 4.9.74-unofficial+grsec #9 SMP PREEMPT Fri Jan 19 09:32:26 EET 2018 x86_64 Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz GenuineIntel GNU/Linux
nginx -V: nginx version: nginx/1.13.9
built by gcc 6.4.0 (Alpine 6.4.0)
built with OpenSSL 1.0.2n 7 Dec 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module

Description

I'm running nginx in a docker with config like this:

server {
    listen 443 ssl http2 default_server deferred;
    server_name _;
    ...
    location ^~ /dir/ {
        proxy_pass ...
    }
}

Problem is, response to https://localhost:8443/dir doesn't include port:

Location: https://localhost/dir/

Adding absolute_redirect off; worked around this issue, but I believe current behaviour is wrong and this use case should not require absolute_redirect off;.

I'm using nginx:alpine image.

Can be related to #1145 and #1000.

Change History (1)

comment:1 by Maxim Dounin, 6 years ago

Resolution: duplicate
Status: newclosed

As of now, nginx supports the following options:

  • use port of the listening socket (with port_in_redirect on), or
  • do not use port in redirects at all (with port_in_redirect off).

No option to use port as given in the Host header is currently available, and that's why your configuration with port 8443 mapped by Docker into listening socket with port 443 does not work. Assuming port_in_redirect on, which is the default, nginx uses port from the listening socket - default in this case, so it is not added to URI.

There are two possible solutions to work properly in the configuration in question: use absolute_redirect off or use port from the Host header. The latter is a feature described in #1145, so closing this as a duplicate of #1145.

Note: See TracTickets for help on using tickets.