Welcome! Log In Create A New Profile

Advanced

Nginx bug when mixing map and try_files ?

Marcin Wanat
October 07, 2020 12:52PM
Hi,

i am doing simple webp client support check using map and then using
try_files to check if file exists and serve it.

Nginx 1.18, my complete nginx.conf:
events {
use epoll;
worker_connections 128;
}

http {

# Check if client is capable of handling webp
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}

server {
listen *:8888;
server_name test;
root /srv;

location ~ ^/imgs/([0-9]*)/(.*)$ {
add_header X-webp $webp_suffix;
try_files /imgs/$1$webp_suffix
/imgs/$1.jpg =404;
}

}
}

Now i am opening:
http://test:8888/imgs/10/whatever

And it results in error 404.
Files /srv/imgs/10.jpg and /srv/imgs/10.webp do exist.

When i spoof my client and remove webp from http accept list, then
everything works ok and serve .jpg.
When i change order of try_files arguments from:
/imgs/$1$webp_suffix /imgs/$1.jpg
to:
/imgs/$1.jpg /imgs/$1$webp_suffix
than it works too and serve .jpg

I have added "add_header" to check if map webp detection works and it
results in:
X-webp .webp
header when webp support enabled in client, so map is working as expected.

What am i missing ?

1) Why it does not serve .webp file at all ?
2) Why when try_files has webp check on first position it DO NOT serve .jpg
file but 404 and when i swap order of parameters i DO serve .jpg ?

Regards,
Marcin Wanat
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx bug when mixing map and try_files ?

Marcin Wanat October 07, 2020 12:52PM

Re: Nginx bug when mixing map and try_files ?

Francis Daly October 07, 2020 02:10PM

Re: Nginx bug when mixing map and try_files ?

Marcin Wanat October 07, 2020 02:36PM

Re: Nginx bug when mixing map and try_files ?

Mr Alex October 07, 2020 02:44PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 52
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready