How can I prevent hotlinking? (nginx)

I use nginx and I have no access to server conf.

May be with .htaccess analogue?..


Solution 1:

Without access to the server configuration, you cannot change any settings. There is no equivalent to Apache httpd's .htaccess in nginx.

Solution 2:

location ~* (\.jpg|\.png|\.gif|\.jpeg)$ {
 valid_referers blocked www.domain.com domain.com;
 if ($invalid_referer) {
    return 403;
 }
  root   /srv/www/domain.com/public_html;
}

Solution 3:

Just in case you HAVE access to the webserver:

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