0

I am using nginx as a reverse proxy with apache.

I have added this code to prevent hotlinking, and it is working fine so far.

#hotlinking protection
location ~* \.(png|gif|jpg|jpeg)$ {
valid_referers none blocked mydomain.com *.mydomain.com;
    if ($invalid_referer){
    return 403;
    }
}

How can I make it so when somebody tries to hotlink an image, instead of a 403 error, he will get a specific anti-hotlinking image?

I tried

return 301 h++p://i.imgur.com/mypicturename.png;

but it didnt work.

I don't know very much about nginx yet, every help will be very appreciated!

1 Answers1

0

You can put a rewrite rule inside of the if instead of the return.

Somthing like

rewrite (.*) http://i.imgur.com/mypicturename.png redirect;

might do the trick.

Christopher Perrin
  • 4,741
  • 17
  • 32