Does the expires directive add the head if the Expire head not exist?

Maxim Dounin mdounin at
Mon Aug 18 02:33:08 MSD 2008


On Sun, Aug 17, 2008 at 07:27:38PM +0800, Delta Yeh wrote:

>I use
>location / {
>            proxy_redirect   off;
>            proxy_redirect   default;


"proxy_redirect default" is useless here since redirects was 
switched off by "proxy_redirect off".

>            #if ( $request_uri ~* ^.+.(css|jpg|jpeg|gif)$ ) {


Since last dot in regex isn't escaped, this expression will match 
something like "/some-notes-about-css" as well as "/style.css".

>            if ( $content_type ~* css ) {

Variable $content_type contains Content-Type header value from 
*request*.  It's unlikely that request will contain css in it's 


>               expires 1h;
>            }
>            proxy_pass http://my_upstream;
>        }
>but it does not work.
>when I use $request_uri the browser get error response. It seems the nginx
>box reset the tcp connection.

I've just checked and with $request_uri it works as expected. I.e.  
nginx adds Expires and Cache-Control headers to response if .

Try tcpdump / error log / error log at debug level to figure out 
what's actually happening.

>when I use $content_type  no Expires head returned by nginx.

Also as expected, see above.

Maxim Dounin

More information about the nginx mailing list