Forum: NGINX Rewriting for revisioned URLs

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E2f0e5c8a12d350b4953069f558da176?d=identicon&s=25 Brian Kirkbride (Guest)
on 2009-05-21 18:07
(Received via mailing list)
Hi all,

I'm trying to switch us from LigHTTPD to NginX and have run into some
issues.  Any help is much appreciated.

We use revisioned URLs to allow for far-future caching of resources
(e.g. http://example.com/r1234567890/site.css) and are having trouble
getting this to work.

Basically we need to strip /r1234567890 from the front of the URI and
set expires to max, then check for a file and fallback to FastCGI.

I've tried something like:


location ~ ^/r[0-9]+ {
     if ( $uri ~ ^/r([0-9]+)(/.*)$ ) {
         set $rev $1;
         set $realuri $2;
     }
     expires max;
     try_files $root/$realuri @catalyst;
}


with no luck.  Any ideas?

Thanks in advance!
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-05-21 18:16
(Received via mailing list)
On Thu, May 21, 2009 at 10:50 PM, Brian Kirkbride
<brian.kirkbride@deeperbydesign.com> wrote:
> expires to max, then check for a file and fallback to FastCGI.
>
> I've tried something like:
>
>
> location ~ ^/r[0-9]+ {
>    if ( $uri ~ ^/r([0-9]+)(/.*)$ ) {
>        set $rev $1;
c>        set $realuri $2;
>    }
>    expires max;
>    try_files $root/$realuri @catalyst;

try_files $realuri @catalyst;

?
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-05-21 18:19
(Received via mailing list)
On Thu, May 21, 2009 at 11:09 PM, Edho P Arief <edhoprima@gmail.com>
wrote:
>>
>>    }
>>    expires max;
>>    try_files $root/$realuri @catalyst;
>
> try_files $realuri @catalyst;
>
> ?
>

also iirc you can regex the location

location ~ ^/r([0-9]+)(/.*)$ {
set $rev $1;
set $realuri $2;
expires max;
try_files $realuri @catalyst;
}

(or something like that)
14eddebaded16496d1198b2e43d44946?d=identicon&s=25 Jauder Ho (jauderho)
on 2009-05-21 19:00
Brian Kirkbride wrote:

>
>
> location ~ ^/r[0-9]+ {
>      if ( $uri ~ ^/r([0-9]+)(/.*)$ ) {

> Thanks in advance!

Your regex is bad and is trying to match from the beginning of the
string. Try /r([0-9]+)(/.*)$ instead.

Check it with http://www.regextester.com/
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-21 19:13
(Received via mailing list)
On Thu, May 21, 2009 at 10:50:04AM -0500, Brian Kirkbride wrote:

> set expires to max, then check for a file and fallback to FastCGI.
>     try_files $root/$realuri @catalyst;
> }
>
>
> with no luck.  Any ideas?

location ~ ^/r\d+(/.*)$ {
    expires max;
    try_files  $1  @catalyst;
}
E2f0e5c8a12d350b4953069f558da176?d=identicon&s=25 Brian Kirkbride (Guest)
on 2009-05-21 20:12
(Received via mailing list)
Igor Sysoev wrote:
>>
>>     }
> }
>
>

Thanks Igor, but no luck.  It always falls back to @catalyst, even
when the file exists.  I have debugging enabled and logging, but I
don't see anything in the error log to show where it is looking.

I also tried this as well with no luck:

location ~ ^/r\d+(/.*)$ {
    set $look $1;
    expires max;
    try_files  $look  @catalyst;
}

This is on 0.6.36 btw.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-21 20:17
(Received via mailing list)
On Thu, May 21, 2009 at 01:02:50PM -0500, Brian Kirkbride wrote:

> >>getting this to work.
> >>        set $realuri $2;
> >    try_files  $1  @catalyst;
> location ~ ^/r\d+(/.*)$ {
>    set $look $1;
>    expires max;
>    try_files  $look  @catalyst;
> }
>
> This is on 0.6.36 btw.

Probably you need to set "root" inside this location or at server level.
14eddebaded16496d1198b2e43d44946?d=identicon&s=25 Jauder Ho (jauderho)
on 2009-05-21 20:38
Brian,

As I said, your original regex is wrong. You need to remove the ^

--Jauder
E2f0e5c8a12d350b4953069f558da176?d=identicon&s=25 Brian Kirkbride (Guest)
on 2009-05-21 21:02
(Received via mailing list)
Thanks Jauder, but that didn't solve it.
This topic is locked and can not be replied to.