Aug 182010
 

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
}

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.