<div dir="ltr"><div>Hi,</div><div><br></div><div>i am doing simple webp client support check using map and then using try_files to check if file exists and serve it.</div><div><br></div><div>Nginx 1.18, my complete nginx.conf:</div><div>events {<br> use epoll;<br> worker_connections 128;<br>}<br><br>http {<br><br> # Check if client is capable of handling webp<br> map $http_accept $webp_suffix {<br> default "";<br> "~*webp" ".webp";<br> }<br><br> server {<br> listen *:8888;<br> server_name test;<br> root /srv;<br><br> location ~ ^/imgs/([0-9]*)/(.*)$ {<br> add_header X-webp $webp_suffix;<br> try_files /imgs/$1$webp_suffix /imgs/$1.jpg =404;<br> }<br><br> }<br>}</div><div><br></div><div>Now i am opening:<br><a href="http://test:8888/imgs/10/whatever">http://test:8888/imgs/10/whatever</a></div><div><br></div><div>And it results in error 404.</div><div>Files /srv/imgs/10.jpg and
/srv/imgs/10.webp do exist. <br></div><div><br></div><div>When i spoof my client and remove webp from http accept list, then everything works ok and serve .jpg.<br></div><div>When i change order of try_files arguments from:<br>
/imgs/$1$webp_suffix /imgs/$1.jpg
<br></div><div>to:<br>/imgs/$1.jpg
/imgs/$1$webp_suffix
<br></div><div>than it works too and serve .jpg<br></div><div><br></div><div>I have added "add_header" to check if map webp detection works and it results in:<br></div><div>X-webp .webp<br></div><div>header when webp support enabled in client, so map is working as expected.</div><div><br></div><div>What am i missing ?<br></div><div><br></div><div>1) Why it does not serve .webp file at all ?<br></div><div>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 ?</div><div><br></div><div>Regards,<br></div><div>Marcin Wanat<br></div></div>