# Rails, Nginx and blocking linked images

**URL:** <https://www.ruby-forum.com/t/rails-nginx-and-blocking-linked-images/113989>\
**Category:** Deployment\
**Created:** [September 6, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/rails-nginx-and-blocking-linked-images/113989 "2007-09-06T22:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [September 6, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/rails-nginx-and-blocking-linked-images/113989/1 "2007-09-06T22:46:17Z")

</div>

Hi Everyone,

Im using the standard rails/mongrel config script  
([http://wiki.codemongers.com/NginxRubyonRailsMongrel](http://wiki.codemongers.com/NginxRubyonRailsMongrel)) for a rails site  
but Im trying to block images from being linked from other sites.

It looks like something like this is supposed to do it:

location ~\* .(gif/jpg/png/swf/flv)$ {  
valid\_referers none blocked mydomain.coml;

if ($invalid\_referer) {  
return 403;  
}  
}

But when I insert this inside the server block (after the location  
/50x.html) line all my images come up as 404 when requested via the  
site…Nginx is pretty hard to work out in these cases…any ideas  
why this is happening?

In fact, even if I put that location block in with nothing in it at  
all it 404s my images…

Cheers,

–  
Dan W.  
[http://www.danwebb.net](http://www.danwebb.net)

Event Wax ([http://www.eventwax.com](http://www.eventwax.com))

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [September 6, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/rails-nginx-and-blocking-linked-images/113989/2 "2007-09-06T22:55:22Z")

</div>

Sorry, the above example should be:

location ~\* .(gif|jpg|png|swf|flv)$ {  
valid\_referers none blocked [mydomain.com](http://mydomain.com);

if ($invalid\_referer) {  
return 403;  
}

}

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [September 10, 2007, 11:48pm UTC](https://www.ruby-forum.com/t/rails-nginx-and-blocking-linked-images/113989/3 "2007-09-10T23:48:53Z")

</div>

Maybe post this to the nginx list?
