Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

May be with .htaccess analogue?..

share|improve this question

5 Answers 5

up vote 4 down vote accepted

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

share|improve this answer
    
-1 Downvoting. This answer does not match the question title. –  unixman83 Mar 29 '12 at 5:48
    
@unixman83 how is this not relative to the question? besides, you're bringing a question that's 4 years old - things usually change for that amount of time. –  tftd Dec 12 '13 at 0:01
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;
}
share|improve this answer
    
is that for the nginx config file? –  blndcat Feb 26 '10 at 2:22
    
Yep, ask your server administrator. –  user29686 Feb 27 '10 at 14:18
    
it should be 'not blocked' in the second line. –  alfish Nov 18 '11 at 18:03
    
@alfish Are you sure? Wouldn't setting not blocked disable the script, allowing all referrers through? –  unixman83 Mar 26 '12 at 0:00

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;
 }
}
share|improve this answer
    
How is this really different from Gionn's answer from 1.5 years ago? –  Chris S Nov 18 '11 at 18:13
    
How is none different from blocked? What is it's purpose of being added? i.e. How is a no referrer different from a blocked referrer? –  unixman83 Mar 29 '12 at 5:49
    
In the valid_referers directive, blocked allows referrers that have been blocked by a firewall, none allows requests with no referrer. From docs "none means the absence of "Referer" header. blocked means masked Referer header by firewall, for example, "Referer: XXXXXXX". –  Dylan Apr 24 '12 at 19:41
    
some browsers do not send a referrer header, so none is required to allow those. apparently Firefox releases have been in this group –  Dylan Apr 24 '12 at 19:49

joschi is right: nginx is driven by a single configuration file you can't edit. Your only possibility is to use a redirector script which says '403 Access Denied' for hotlinks and '301 Moved Permanently' for normal links.

share|improve this answer

One solution is to generate all your pages & content dynamically, and with different URLs every time, which expire after a while. That makes hotlinking impossible.

If that is not practical, you can also check referrer. If you cannot reconfigure nginx, you'll probably have to do it in a scripting language which generates the pages dynamically.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.