Image hotlinking prevention via nginx, valid referers always got 404

i have tried tweaking the nginx config to prevent image hotlinking in my current ghost setup, by adding a location block like this :

location ~ .(gif|ico|png|jpe?g)$ { 
  if ($invalid_referer) {
    return 403;

and included this conf inside :


before the location / block.

and now, invalid referers will get 403 as expected, but all valid referers will get 404 instead of 200.

anyone has any ideas why ?

It looks like you don’t have any routing configured (e.g. try_files or proxy_pass directives)


@vikaspotluri123 ,

yes, you’re right, and thanks for your help again ~