arvias
March 19, 2009, 7:26pm
1
Hi,
I have a setup where I am using nginx with RubyOnRails.
The setup looks simple:
if (!-f $request_filename) {
proxy_pass http://domain1 ;
break;
}
However I have a directory that holds images that sometimes get deleted.
People keep linking to those images and the 404s go to the rails
process.
How can I tell nginx that any request towards:
/images/subassets/*.gif
should never be forwarded to rails?
arvias
March 19, 2009, 7:36pm
2
Here’s a simplified version of I use the following to accomplish this,
inside my location block:
if ($uri ~* (.css|.js|.ico|.gif|.jpg|.png)) {
break;
}
Note that I haven’t tested this simplified form directly, but I believe
it
should work.
arvias
March 19, 2009, 8:29pm
3
You can also turn that into a regex location (or location with captures
in
0.7) and take it out of the main location block. I am not 100% sure,
but my
intuition tells me that the location block performs much (well, at least
a
little) better than the if block. It looks cleaner, anyway :).
arvias
March 19, 2009, 9:32pm
4
On Thu, 2009-03-19 at 20:14 +0200, Marcelo B. wrote:
However I have a directory that holds images that sometimes get deleted.
People keep linking to those images and the 404s go to the rails process.
How can I tell nginx that any request towards:
/images/subassets/*.gif
should never be forwarded to rails?
location ~ /images/subassets/*.gif {
root /path/to/root;
}
location / {
root /path/to/root;
error_page 404 = @rails ;
}
location @rails {
proxy_pass http://domain.com ;
}
If you don’t want anything from the subassets folder (not just gifs)
to be passed to Rails, then just use
location /images/subassets {
root /path/to/root;
}
Cliff
arvias
March 19, 2009, 9:32pm
5
On Thu, 2009-03-19 at 13:21 -0700, Cliff W. wrote:
Oops, should be
location ~ /images/subassets/*.gif {
location ~ /images/subassets/*..gif$ {
arvias
March 19, 2009, 9:43pm
6
On Thu, Mar 19, 2009 at 12:18:50PM -0700, Merlin wrote:
You can also turn that into a regex location (or location with captures in
0.7) and take it out of the main location block. I am not 100% sure, but my
intuition tells me that the location block performs much (well, at least a
little) better than the if block. It looks cleaner, anyway :).
Yes, better and much, much cleaner.
arvias
March 19, 2009, 9:43pm
7
On Thu, Mar 19, 2009 at 01:26:29PM -0500, Nick P. wrote:
Here’s a simplified version of I use the following to accomplish this,
inside my location block:
if ($uri ~* (.css|.js|.ico|.gif|.jpg|.png)) {
break;
}
Note that I haven’t tested this simplified form directly, but I believe it
should work.
“if ($uri ~” or “if ($request_filename ~” means that you should use
locations as here:
location / {
…
}
location ~* .(?:css|js|ico|gif|jpg|png)$ {
…
}
arvias
March 19, 2009, 10:20pm
8
On Thu, Mar 19, 2009 at 01:37:08PM -0700, Cliff W. wrote:
location ~ /images/subassets/.*.gif$ {
Yes
location ~ ^/images/subassets/.*.gif$ {
arvias
March 20, 2009, 12:24am
9
Hi,
I placed something like:
location ~
/images/(tassets|bassets)/(fullsize|thumb)/.+(.gif|.jpg|.png) {
root /path/to/root/;
}
Images stopped being loaded after that.
The only weird thing is that both tassets/ and bassets/ are symlinks.
arvias
March 19, 2009, 10:15pm
10
On Thu, 2009-03-19 at 13:22 -0700, Cliff W. wrote:
On Thu, 2009-03-19 at 13:21 -0700, Cliff W. wrote:
Not a good regex day for me…
Oops, should be
location ~ /images/subassets/*.gif {
location ~ /images/subassets/*..gif$ {
location ~ /images/subassets/.*.gif$ {
Cliff
arvias
March 20, 2009, 12:43am
12
Never mind.
It worked! I entered the root variable incorrectly.
Thanks!