5

I have my static assets configured as

 location @upstream {
   proxy_pass http://localhost:82;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 }

 location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
     try_files $uri @upstream;
     access_log off;
     expires max;
     add_header Cache-Control public;
 }

The expires max is not respected.
I think its respecting the incoming server header.

How can modify this to set expires header?

1 Answer 1

3

Nginx only ever applies one location, never more. In your example it will apply the expires header to existing static files, but any files not found and thus coming from the @upstream location will ignore access_log, expires and add_header directives from static location.

If you want to set expires you should duplicate the directive across both locations. Setting proxy_hide_header might also be required.

2
  • worked like a charm. why would i need hide header? Sep 26, 2011 at 17:12
  • In case your proxy sets an expire of its own you might need it to make sure your nginx one takes effect. Sep 26, 2011 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .