Welcome! Log In Create A New Profile

Advanced

try_files and a nested location regexp

October 16, 2014 05:38AM
I could not figure out why try_files in a nested location defined with a regexp does not work in nginx/1.4.6 under Ubuntu 14.04. Consider the following config:

server {
listen 8080 default_server;
root /usr/share/nginx/html;
autoindex on;

location /x/ {
alias /test/;
location ~ ^/x/test {
try_files $uri =404;
}
}
}

With /test containing publically readable file test.html and directory test_dir this does not works as expected. While localhost:/x/ properly lists directory context of /test and localhost:/x/test_dir/ is reported as 404 not found , nginx also reported as 404 not found localhost:/x/test.html even if the file exists.

Now, if replace the regexp with a simple prefix so the location reads:

location /x/ {
alias /test/;
location /x/test {
try_files $uri =404;
}
}

then everything work. That is, both localhost:/x/ and localhost:/x/test.html are accessible and only localhost:/x/test_dir/ is 404 not found.

So what is wrong with the usage of try_files in the initial regexp-based location config?
Subject Author Posted

try_files and a nested location regexp

igorb October 16, 2014 05:38AM

Re: try_files and a nested location regexp

Sergey Kandaurov October 16, 2014 06:02AM

Re: try_files and a nested location regexp

igorb October 16, 2014 07:09AM

Re: try_files and a nested location regexp

Edho Arief October 16, 2014 07:14AM

Re: try_files and a nested location regexp

igorb October 16, 2014 07:25AM

Re: try_files and a nested location regexp

Edho Arief October 16, 2014 07:42AM

Re: try_files and a nested location regexp

igorb October 16, 2014 08:03AM

Re: try_files and a nested location regexp

Edho Arief October 16, 2014 08:32AM

Re: try_files and a nested location regexp

Francis Daly October 16, 2014 07:30AM

Re: try_files and a nested location regexp

igorb October 16, 2014 07:55AM

Re: try_files and a nested location regexp

Francis Daly October 16, 2014 08:20AM

Re: try_files and a nested location regexp

igorb October 16, 2014 08:42AM

Re: try_files and a nested location regexp

Francis Daly October 16, 2014 09:20AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 303
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready