I bumped into the same issue when trying to setup NGINX to serve WebP files from the same filename as JPG/PNG's and certain files were containing spaces. The reason why it happens like this is:
- space cannot be used inside of an URL and browsers replace it automatically inside the URL with
%20, as you might be aware
$uri variable in this case will contain the link with
%20 as you can see from the logs
- when NGINX is looking for the file with
%20 in its name on the disk, it will not find it, because on disk it is stored with space and not with
%20, therefore it will result in a 404.
A potential way of getting this to work is to do a replacement of the
%20 with a space and the only way of achieving this that comes to my mind is to use something like OpenRestly's Lua NGINX Module:
Then, after this is properly installed and configured (not very easy!), you might try something like this, just before
ngx.var.uri = string.gsub(ngx.var.uri, "%20", " ")
This isn't actually tested, it's just an idea. If there are better ways to achieve this, I'm open to check them!