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
}