# Preventing hotlinking at "http" level, not server by server

**URL:** <https://www.ruby-forum.com/t/preventing-hotlinking-at-http-level-not-server-by-server/219795>\
**Category:** NGINX\
**Created:** [May 16, 2012, 12:23pm UTC](https://www.ruby-forum.com/t/preventing-hotlinking-at-http-level-not-server-by-server/219795 "2012-05-16T12:23:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 16, 2012, 12:23pm UTC](https://www.ruby-forum.com/t/preventing-hotlinking-at-http-level-not-server-by-server/219795/1 "2012-05-16T12:23:09Z")

</div>

Hi. There are many code samples on the web for simple hotlinking.

I have some questions on how to do this in a better way, and all my  
trial code has not worked, so hope some Nginx guru here can help.

Here’s what I am looking for:

1. Firstly, I would like the blocking to happen at a server-wide level.  
Nginx is on a dedicated server, and there are many “server” vhost tags  
in a folder. I prefer not to have to write the blocking code for every  
server individually. Is this possible at an “http” level? What’s the  
code for that.

2. Secondly, I have about 35 domains and many subdomains. I don’t want  
them to be in one long line. But all my “vhost” server tags are inside a  
directory. Can I somehow specify Nginx to allow all those domains whose  
server definitions are in a folder? (/etc/nginx/vhosts)

3. Will the “IF” condition slow down my Nginx? I remember reading that  
Nginx does not like IF conditions.

4. I want to allow some additional domains like Google and Facebook and  
Pinterest. What’s a good way to include this in the allowable list.

5. Finally, if I do have to include this directive in each “server”  
block for each of my domains, can I at least bundle the commands for  
these type of files as such:

`------  
location ~\* .(png|gif|jpg|jpeg|swf|ico|)$ {  
expires 7d;  
try\_files $uri @backend;

```
  valid_referers none blocked site.com mysite.com ~\.google\.

```

~.yahoo. ~.bing. ~.facebook. ~.fbcdn.;  
if ($invalid\_referer) {  
return 403;  
}

```
}

```

------`

Thanks!

Posted at Nginx Forum:

> **[Preventing hotlinking at "http" level, not server by server..](https://forum.nginx.org/read.php?2,226491,226491#msg-226491)**
>
> Hi. There are many code samples on the web for simple hotlinking. I have some questions on how to do this in a better way, and all my trial code has not worked, so hope some Nginx guru here can help. Here's what I am looking for: 1. Firstly, I would...

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [May 26, 2012, 7:42pm UTC](https://www.ruby-forum.com/t/preventing-hotlinking-at-http-level-not-server-by-server/219795/2 "2012-05-26T19:42:34Z")

</div>

Any ideas at all?

Thanks.

Posted at Nginx Forum:

> **[Re: Preventing hotlinking at "http" level, not server by server..](https://forum.nginx.org/read.php?2,226491,226858#msg-226858)**
>
> Hi. There are many code samples on the web for simple hotlinking. I have some questions on how to do this in a better way, and all my trial code has not worked, so hope some Nginx guru here can help. Here's what I am looking for: 1. Firstly, I would...
