﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
1434	Strange behaviour with' if' & 'try_files' directives inside a 'location'.	enrico-sorcinelli@…		"I used simple configuration with `if` & `try_files` inside a `location` block like following (placed into original ''nginx.conf''):

{{{
server {

	# Specific error log
	error_log logs/bug_error_log debug;

	# Listen port for ipv4
	listen 9000;

	# Define root HTML dir
	root html;
	index index.html index.htm;

	# Server name
	server_name localhost;

	# Location for bug test
	location ~ ^/ok/(?<foo>.*) {
		set $baz $1;
		if ( $baz = ""Foo"" ) {
			set $baz ""bar"";
		} 
		try_files /$foo =404;
	}

	# Location for bug test
	location ~ ^/ko/(?<foo>.*) {
		set $baz $1;
		if ( $baz != ""Foo"" ) {
			set $baz ""bar"";
		} 
		try_files /$foo =404;
	}
}
}}}

By requesting a URL like ''http://localhost:9000/ok/index.html'' the server returns `200` as espected.
However requesting ''http://localhost:9000/ko/index.html'' causes the server  wrongly to respond with `404`.

The only thing that changes between two `location`s is the use of negative operator inside `if` directive.

So it seems that the apparenlty this wrong behaviour is caused by the use of the negative operator in the `ko` `location` block.

It's a bug or I missing something in the configuration?
This behaviour affects both `1.12.2` and `1.13.6` versions.


Debug log for ''http://localhost:9000/ko/index.html'' request:
{{{
2017/11/22 14:16:22 [debug] 17713#0: *33 using configuration ""^/ko/(?<foo>.*)""
2017/11/22 14:16:22 [debug] 17713#0: *33 http cl:-1 max:1048576
2017/11/22 14:16:22 [debug] 17713#0: *33 rewrite phase: 3
2017/11/22 14:16:22 [debug] 17713#0: *33 http script complex value
2017/11/22 14:16:22 [debug] 17713#0: *33 http script capture: ""index.html""
2017/11/22 14:16:22 [debug] 17713#0: *33 http script set $baz
2017/11/22 14:16:22 [debug] 17713#0: *33 http script var
2017/11/22 14:16:22 [debug] 17713#0: *33 http script var: ""index.html""
2017/11/22 14:16:22 [debug] 17713#0: *33 http script value: ""Foo""
2017/11/22 14:16:22 [debug] 17713#0: *33 http script not equal
2017/11/22 14:16:22 [debug] 17713#0: *33 http script if
2017/11/22 14:16:22 [debug] 17713#0: *33 http script value: ""bar""
2017/11/22 14:16:22 [debug] 17713#0: *33 http script set $baz
2017/11/22 14:16:22 [debug] 17713#0: *33 post rewrite phase: 4
2017/11/22 14:16:22 [debug] 17713#0: *33 generic phase: 5
2017/11/22 14:16:22 [debug] 17713#0: *33 generic phase: 6
2017/11/22 14:16:22 [debug] 17713#0: *33 generic phase: 7
2017/11/22 14:16:22 [debug] 17713#0: *33 access phase: 8
2017/11/22 14:16:22 [debug] 17713#0: *33 access phase: 9
2017/11/22 14:16:22 [debug] 17713#0: *33 post access phase: 10
2017/11/22 14:16:22 [debug] 17713#0: *33 generic phase: 11
2017/11/22 14:16:22 [debug] 17713#0: *33 generic phase: 12
2017/11/22 14:16:22 [debug] 17713#0: *33 content phase: 13
2017/11/22 14:16:22 [debug] 17713#0: *33 content phase: 14
2017/11/22 14:16:22 [debug] 17713#0: *33 content phase: 15
2017/11/22 14:16:22 [debug] 17713#0: *33 content phase: 16
2017/11/22 14:16:22 [debug] 17713#0: *33 content phase: 17
2017/11/22 14:16:22 [debug] 17713#0: *33 http filename: ""/working/lib/nginx-1.13.6/html/ko/index.html""
2017/11/22 14:16:22 [debug] 17713#0: *33 add cleanup: 000000000233CE68
2017/11/22 14:16:22 [error] 17713#0: *33 open() ""/working/lib/nginx-1.13.6/html/ko/index.html"" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: ""HEAD /ko/index.html HTTP/1.1"", host: ""localhost:9000""
}}}


Debug log for ''http://localhost:9000/ok/index.html'' request:
{{{
2017/11/22 14:20:05 [debug] 17713#0: *34 using configuration ""^/ok/(?<foo>.*)""
2017/11/22 14:20:05 [debug] 17713#0: *34 http cl:-1 max:1048576
2017/11/22 14:20:05 [debug] 17713#0: *34 rewrite phase: 3
2017/11/22 14:20:05 [debug] 17713#0: *34 http script complex value
2017/11/22 14:20:05 [debug] 17713#0: *34 http script capture: ""index.html""
2017/11/22 14:20:05 [debug] 17713#0: *34 http script set $baz
2017/11/22 14:20:05 [debug] 17713#0: *34 http script var
2017/11/22 14:20:05 [debug] 17713#0: *34 http script var: ""index.html""
2017/11/22 14:20:05 [debug] 17713#0: *34 http script value: ""Foo""
2017/11/22 14:20:05 [debug] 17713#0: *34 http script equal
2017/11/22 14:20:05 [debug] 17713#0: *34 http script equal: no
2017/11/22 14:20:05 [debug] 17713#0: *34 http script if
2017/11/22 14:20:05 [debug] 17713#0: *34 http script if: false
2017/11/22 14:20:05 [debug] 17713#0: *34 post rewrite phase: 4
2017/11/22 14:20:05 [debug] 17713#0: *34 generic phase: 5
2017/11/22 14:20:05 [debug] 17713#0: *34 generic phase: 6
2017/11/22 14:20:05 [debug] 17713#0: *34 generic phase: 7
2017/11/22 14:20:05 [debug] 17713#0: *34 access phase: 8
2017/11/22 14:20:05 [debug] 17713#0: *34 access phase: 9
2017/11/22 14:20:05 [debug] 17713#0: *34 post access phase: 10
2017/11/22 14:20:05 [debug] 17713#0: *34 generic phase: 11
2017/11/22 14:20:05 [debug] 17713#0: *34 try files handler
2017/11/22 14:20:05 [debug] 17713#0: *34 http script copy: ""/""
2017/11/22 14:20:05 [debug] 17713#0: *34 http script var: ""index.html""
2017/11/22 14:20:05 [debug] 17713#0: *34 trying to use file: ""/index.html"" ""/working/lib/nginx-1.13.6/html/index.html""
2017/11/22 14:20:05 [debug] 17713#0: *34 try file uri: ""/index.html""
2017/11/22 14:20:05 [debug] 17713#0: *34 generic phase: 12
2017/11/22 14:20:05 [debug] 17713#0: *34 content phase: 13
2017/11/22 14:20:05 [debug] 17713#0: *34 content phase: 14
2017/11/22 14:20:05 [debug] 17713#0: *34 content phase: 15
2017/11/22 14:20:05 [debug] 17713#0: *34 content phase: 16
2017/11/22 14:20:05 [debug] 17713#0: *34 content phase: 17
2017/11/22 14:20:05 [debug] 17713#0: *34 http filename: ""/working/lib/nginx-1.13.6/html/index.html""
}}}
"	defect	closed	major		nginx-core	1.13.x	duplicate			Linux maya 4.10.0-38-generic #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux	"nginx version: nginx/1.13.6
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/working/lib/nginx-1.13.6 --with-debug --with-http_image_filter_module --with-http_secure_link_module --with-http_addition_module --with-http_dav_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-cc-opt='-I/working/lib/pcre-8.41/include -I/working/lib/libgd-2.2.5/include' --with-ld-opt='-L/working/lib/pcre-8.41/lib -L/working/lib/libgd-2.2.5/lib'

**********************************

nginx version: nginx/1.12.2
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/working/lib/nginx-1.12.2 --with-debug --with-http_image_filter_module --with-http_secure_link_module --with-http_addition_module --with-http_dav_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-cc-opt='-I/working/lib/pcre-8.41/include -I/working/lib/libgd-2.2.5/include' --with-ld-opt='-L/working/lib/pcre-8.41/lib -L/working/lib/libgd-2.2.5/lib'
"
