Nginx Image Hotlink Prevention

how to prevent image hotlinking with nginx?
this will return 403 error when someone trying to use image directly from oursite.

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

or we can change every images which hotlinked with our custom banner.

valid_referers  none blocked  www.example.com  example.com;
if ($invalid_referer) {
    rewrite ^/images/(.*)\.(gif|jpg|jpeg|png)$ http://www.example.com/banner.jpg last
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *