Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
worked like a charm. why would i need hide header? –  Quintin Par Sep 26 '11 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. –  Martin Fjordvald Sep 26 '11 at 17:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.