Expiration headers when rewriting requests

Igor Sysoev is at rambler-co.ru
Wed Mar 12 00:52:17 MSK 2008


On Tue, Mar 11, 2008 at 04:27:46PM -0500, Brian Kirkbride wrote:

> Hello,
> 
> I'm having trouble translating my setup into a working NginX config. 
> Any help is much appreciated -- I'm almost there, but not quite.
> 
> 
> I need to rewrite URLs like /r1234567/xyz... to be simply /xyz... to 
> allow for versioned caching of resources (cache forever, change 
> revision in URL to force cache update).
> 
> A simple rewrite rule works to find the resource, but I need to set 
> the expiration headers to max for requests like this.  I tried doing this:
> 
> location ~ ^/r[0-9]+/ {
>     expires max;
>     add_header Last-Modified "Thu, 01 Jan 1970 00:00:01 GMT"
>     rewrite ^/r[0-9]+(/.*)$ $1 last;
> }
> 
> location / {
>     # check for a cached file, fallback to FastCGI, etc
> }
> 
> But this doesn't work because the rewrite seems to wipe out the 
> headers when starting the request over.  I tried the rewrite with 
> last, break and no flags -- nothing worked.

After rewrite nginx uses new location configuration unless you use break:

 location ~ ^/r[0-9]+/ {
     expires max;
     add_header Last-Modified "Thu, 01 Jan 1970 00:00:01 GMT"
-    rewrite ^/r[0-9]+(/.*)$ $1 last;
+    rewrite ^/r[0-9]+(/.*)$ $1 break;
 }

However, it will not work after fallback to FastCGI.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list