Opened 10 years ago

Closed 4 years ago

#431 closed defect (fixed)

directory redirect ex: try_files $uri $uri/ @backend;

Reported by: Роман Матиевский Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.3.x
Keywords: directory redirect Cc:
uname -a: Linux irserver 3.5.0-42-generic #65~precise1-Ubuntu SMP Wed Oct 2 20:57:18 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: ngx_openresty/1.4.2.9
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --add-module=../ngx_devel_kit-0.2.19 --add-module=../echo-nginx-module-0.48 --add-module=../xss-nginx-module-0.03rc9 --add-module=../ngx_coolkit-0.2rc1 --add-module=../set-misc-nginx-module-0.22 --add-module=../form-input-nginx-module-0.07 --add-module=../encrypted-session-nginx-module-0.03 --add-module=../srcache-nginx-module-0.22 --add-module=../ngx_lua-0.9.0 --add-module=../headers-more-nginx-module-0.22 --add-module=../array-var-nginx-module-0.03rc1 --add-module=../memc-nginx-module-0.13 --add-module=../redis2-nginx-module-0.10 --add-module=../redis-nginx-module-0.3.6 --add-module=../auth-request-nginx-module-0.2 --add-module=../rds-json-nginx-module-0.12rc10 --add-module=../rds-csv-nginx-module-0.05rc2 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --sbin-path=/usr/local/sbin --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/nginx-error.log --http-log-path=/var/log/nginx/nginx-http.log --pid-path=/var/run/nginx.pid --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=www-data --group=www-data --with-file-aio --with-ipv6 --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-mail --add-module=/home/superuser/src/nginx-upload-progress-module --with-http_ssl_module

Description

Пример:

server {
   listen 8000;
   server_name domain1 domain2 domain3 [somedomain...] ; 
[...]
location / {
       try_files $uri $uri/ @backend;
[...]

как известно, в случае существования директории $uri происходит 301 редирект.

но: telnet domain3 8000

GET /existdir HTTP/1.1
host: domain2:9999

выдает

HTTP/1.1 301 Moved Permanently
Server: ngx_openresty/1.4.2.9
Date: Thu, 31 Oct 2013 12:03:06 GMT
Content-Type: text/html
Content-Length: 194
Location: http://domain2:8000/existdir/
Connection: keep-alive

<html>
<head><title>301 Moved Permanently</title></head>
[...]

Здесь
domain2:8000/existdir/

происходит игнорирование оригинального порта на котором был произведен запрос, хотя домен сохраняется.
Таким образом редирект отказывается нерабочим, если на сервере происходит перенаправление порта (например туннель на отличающийся порт).

Change History (2)

comment:1 by Роман Матиевский, 10 years ago

port_in_redirect off;

вероятно решает эту проблему.

comment:2 by Maxim Dounin, 4 years ago

Resolution: fixed
Status: newclosed

The port_in_redirect directive provides a way to omit ports from redirects and covers most cases when nginx is configured behind a proxy/tunnel. If the proxy/tunnel also uses non-default port, the absolute_redirect directive can be switched off, as introduced in nginx 1.11.8.

Note: See TracTickets for help on using tickets.