0
votes

I'm using nginx as a proxy (with location /) and trying to serve a static image for hotlink protection redirects under another location block. The following is what I am using to try to serve the image. I've moved the root directive outside of the location block which was necessary for nginx to build a proper path for some reason.

location = /hotlink.png {
    autoindex off;
    try_files hotlink.png hotlink.png
}

However, when I look at the log, it is still looking for an index.html by appending the URI to the root path: {root}/hotlink.png/index.html. I simply want it to only send the file {root}/hotlink.png when /hotlink.png is matched and that's it.

Why is it still looking for an index with autoindex off? How can I fix this or is there a better way to handle this case in general?

1
Remove the try_files statement. - Richard Smith
@RichardSmith That is what I initially had. Without try_files it seems to be skipping the block altogether and falling back the location / block - user1137704
Is hotlink.png a real file? - Richard Smith
Yes, it is a real file - user1137704

1 Answers

0
votes

After changing gears and coming back to this, I got it working by simply moving the autoindex off directive outside of the location block as well. It works with or without the try_files directive. I left it out for terseness and to avoid redundancy

root /path/to/static/files;
autoindex off;

location / {
   # proxy
}

location = /hotlink.png {}