Opened 10 years ago

Closed 10 years ago

#434 closed defect (duplicate)

try_files not honored when in location and if + rewrite

Reported by: Jordi Clariana Owned by:
Priority: major Milestone:
Component: nginx-core Version: 1.3.x
Keywords: Cc:
uname -a: Linux server-name 2.6.32-5-xen-amd64 #1 SMP Fri May 10 11:48:05 UTC 2013 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.4.3
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-pcre-jit --with-debug --with-file-aio --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/headers-more-nginx-module --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-auth-pam --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-cache-purge --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-dav-ext-module --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-development-kit --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-echo --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/ngx-fancyindex --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-push-stream-module --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-lua --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-upload-progress --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-upstream-fair --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-syslog --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/ngx_http_pinba_module --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/ngx_http_substitutions_filter_module --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/ngx_pagespeed --add-module=/usr/src/nginx/source/nginx-1.4.3/debian/modules/nginx-x-rid-header --with-ld-opt=-lossp-uuid

Description

Given this vhost:

server {
    listen [::]:80;
    listen 80;
    server_name www.myserver.com;
    root /mnt/www;

    error_log /tmp/nginx_error_debug.log debug;

    location /test {

        set $a "A";
        if ($a = "A") {
            rewrite ^whatever$ $1 break;
        }

        try_files $uri @squid;
    }

    location @squid {
        proxy_pass       http://my_upstream;
    }
}

When I exec:
curl -s -H "HOST: www.myserver.com" http://127.0.0.1/test
The expected behaviour is the request being passed to @squid, and therefore to the proxy_pass.
The actual behaviour is that it doesn't.
Nginx just do the rewrite (that can match or not, it doesn't matter, it fails anyway).

I've tried different conditions in the 'if', different rewrites, tried also moving the try_files outside the location, in server level, etc. But after all, the only thing that works is removing the 'if'.

I think this is clearly a bug.

This is the debug of full request:

2013/11/07 18:20:09 [debug] 23873#0: *572 http header: "HOST: www.myserver.com" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http header done 
2013/11/07 18:20:09 [debug] 23873#0: *572 event timer del: 3: 1383844869677 
2013/11/07 18:20:09 [debug] 23873#0: *572 generic phase: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 rewrite phase: 1 
2013/11/07 18:20:09 [debug] 23873#0: *572 test location: "/test" 
2013/11/07 18:20:09 [debug] 23873#0: *572 using configuration "/test" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http cl:-1 max:52428800 
2013/11/07 18:20:09 [debug] 23873#0: *572 rewrite phase: 3 
2013/11/07 18:20:09 [debug] 23873#0: *572 rewrite phase: 4 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script value: "A" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script set $a 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script var 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script var: "A" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script value: "A" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script equal 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script if 
2013/11/07 18:20:09 [debug] 23873#0: *572 http script regex: "^whatever$" 
2013/11/07 18:20:09 [notice] 23873#0: *572 "^whatever$" does not match "/test", client: 192.168.1.72, server: www.myserver.com, request: "GET /test HTTP/1.1", host: "www.myserver.com" 
2013/11/07 18:20:09 [debug] 23873#0: *572 post rewrite phase: 5 
2013/11/07 18:20:09 [debug] 23873#0: *572 generic phase: 6 
2013/11/07 18:20:09 [debug] 23873#0: *572 generic phase: 7 
2013/11/07 18:20:09 [debug] 23873#0: *572 generic phase: 8 
2013/11/07 18:20:09 [debug] 23873#0: *572 access phase: 9 
2013/11/07 18:20:09 [debug] 23873#0: *572 access phase: 10 
2013/11/07 18:20:09 [debug] 23873#0: *572 access phase: 11 
2013/11/07 18:20:09 [debug] 23873#0: *572 post access phase: 12 
2013/11/07 18:20:09 [debug] 23873#0: *572 pagespeed phase: 13 
2013/11/07 18:20:09 [debug] 23873#0: *572 try files phase: 14 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 15 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 16 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 17 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 18 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 19 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 20 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 21 
2013/11/07 18:20:09 [debug] 23873#0: *572 content phase: 22 
2013/11/07 18:20:09 [debug] 23873#0: *572 http filename: "/mnt/www/test" 
2013/11/07 18:20:09 [debug] 23873#0: *572 add cleanup: 0000000001947180 
2013/11/07 18:20:09 [error] 23873#0: *572 open() "/mnt/www/test" failed (2: No such file or directory), client: 192.168.1.72, server: www.myserver.com, request: "GET /test HTTP/1.1", host: "www.myserver.com" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http finalize request: 404, "/test?" a:1, c:1 
2013/11/07 18:20:09 [debug] 23873#0: *572 http special response: 404, "/test?" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http set discard body 
2013/11/07 18:20:09 [debug] 23873#0: *572 headers more header filter, uri "/test" 
2013/11/07 18:20:09 [debug] 23873#0: *572 uploadprogress error-tracker error: 404 
2013/11/07 18:20:09 [debug] 23873#0: *572 uploadprogress error-tracker not tracking in this location 
2013/11/07 18:20:09 [debug] 23873#0: *572 xslt filter header 
 013/11/07 18:20:09 [debug] 23873#0: *572 HTTP/1.1 404 Not Found
 erver: nginx
 ate: Thu, 07 Nov 2013 17:20:09 GMT
 ontent-Type: text/html
 ontent-Length: 162
 onnection: keep-alive

2013/11/07 18:20:09 [debug] 23873#0: *572 write new buf t:1 f:0 0000000001947210, pos 0000000001947210, size: 148 file: 0, size: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 http write filter: l:0 f:0 s:148 
2013/11/07 18:20:09 [debug] 23873#0: *572 http output filter "/test?" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http copy filter: "/test?" 
2013/11/07 18:20:09 [debug] 23873#0: *572 image filter 
2013/11/07 18:20:09 [debug] 23873#0: *572 xslt filter body 
2013/11/07 18:20:09 [debug] 23873#0: *572 http postpone filter "/test?" 00000000019473D8 
2013/11/07 18:20:09 [debug] 23873#0: *572 write old buf t:1 f:0 0000000001947210, pos 0000000001947210, size: 148 file: 0, size: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 write new buf t:0 f:0 0000000000000000, pos 00000000011B6EE0, size: 116 file: 0, size: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 write new buf t:0 f:0 0000000000000000, pos 00000000011B6880, size: 46 file: 0, size: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 http write filter: l:1 f:0 s:310 
2013/11/07 18:20:09 [debug] 23873#0: *572 http write filter limit 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 writev: 310 
2013/11/07 18:20:09 [debug] 23873#0: *572 http write filter 0000000000000000 
2013/11/07 18:20:09 [debug] 23873#0: *572 http copy filter: 0 "/test?" 
2013/11/07 18:20:09 [debug] 23873#0: *572 http finalize request: 0, "/test?" a:1, c:1 
2013/11/07 18:20:09 [debug] 23873#0: *572 set http keepalive handler 
2013/11/07 18:20:09 [debug] 23873#0: *572 http close request 
2013/11/07 18:20:09 [debug] 23873#0: *572 http log handler 
2013/11/07 18:20:09 [debug] 23873#0: *572 http pinba handler 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 000000000168E0E0, unused: 2 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 0000000001946DA0, unused: 2180 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 00000000018C2370 
2013/11/07 18:20:09 [debug] 23873#0: *572 hc free: 0000000000000000 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 hc busy: 0000000000000000 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 tcp_nodelay 
2013/11/07 18:20:09 [debug] 23873#0: *572 reusable connection: 1 
2013/11/07 18:20:09 [debug] 23873#0: *572 event timer add: 3: 65000:1383844874677 
2013/11/07 18:20:09 [debug] 23873#0: *572 post event 0000000001B978F8 
2013/11/07 18:20:09 [debug] 23873#0: *572 delete posted event 0000000001B978F8 
2013/11/07 18:20:09 [debug] 23873#0: *572 http keepalive handler 
2013/11/07 18:20:09 [debug] 23873#0: *572 malloc: 00000000018C2370:1024 
2013/11/07 18:20:09 [debug] 23873#0: *572 recv: fd:3 -1 of 1024 
2013/11/07 18:20:09 [debug] 23873#0: *572 recv() not ready (11: Resource temporarily unavailable) 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 00000000018C2370 
2013/11/07 18:20:09 [debug] 23873#0: *572 post event 0000000001B978F8 
2013/11/07 18:20:09 [debug] 23873#0: *572 delete posted event 0000000001B978F8 
2013/11/07 18:20:09 [debug] 23873#0: *572 http keepalive handler 
2013/11/07 18:20:09 [debug] 23873#0: *572 malloc: 00000000018C2370:1024 
2013/11/07 18:20:09 [debug] 23873#0: *572 recv: fd:3 0 of 1024 
2013/11/07 18:20:09 [info] 23873#0: *572 client 192.168.1.72 closed keepalive connection 
2013/11/07 18:20:09 [debug] 23873#0: *572 close http connection: 3 
2013/11/07 18:20:09 [debug] 23873#0: *572 event timer del: 3: 1383844874677 
2013/11/07 18:20:09 [debug] 23873#0: *572 reusable connection: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 00000000018C2370 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 0000000001D09A30, unused: 0 
2013/11/07 18:20:09 [debug] 23873#0: *572 free: 00000000019692B0, unused: 104 

Change History (1)

comment:1 by Maxim Dounin, 10 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #86.

Note: See TracTickets for help on using tickets.