Nginx Configuration (with Phusion Passenger) to set Expiration Headers

Added by David Stahl over 12 years ago

We're running Redmine with Nginx and Phusion Passenger. I'd like to set the "expires" header for images, CSS, JS etc...

Has anyone done this? I know this isn't an Nginx forum (I'm about to start posting in some of those :) ) but I'm having all kinds of trouble using recipes that I've found online for much simpler websites and I was hoping someone had already figured it out for the Nginx/Redmine/Phusion config.

Replies (3)

RE: Nginx Configuration (with Phusion Passenger) to set Expiration Headers - Added by Kang-min Liu over 12 years ago

I just did this with the following config:

server {
    passenger_enabled on;

    # .... other config. statements...

    location ~* ^.+.(jpg|jpeg|gif|png|css|js|swf)?([0-9]+)?$ {
        expires max;
        passenger_enabled on;
    }
}

Notice the second line `passenger_enabled` is meant to be there. Without it, the requests for attachments (/attachments/....) will always respond 'not found'.

RE: Nginx Configuration (with Phusion Passenger) to set Expiration Headers - Added by Dmytro Gorbunov almost 12 years ago

regular expression is not correct
it should be

location ~* ^.+\.(jpg|jpeg|gif|png|css|js|swf)\??([0-9]+)?$

or

location ~* \.(jpg|jpeg|gif|png|css|js|swf)(\?[0-9]+)?$

Kind regards,

---
Dmytro Gorbunov
http://savesources.com

RE: Nginx Configuration (with Phusion Passenger) to set Expiration Headers - Added by dj jones almost 8 years ago

THis will also break -because Redmine uses some files .js - to contain user data.

( THis is not ideal of Redmine, as .js files should in general only be files containg static javascript, not user data.)

The symptoms of it breaking will be problems when

  • when attaching a file
  • when editing an existing Journal within an issue

Try this nginx config:

location ~* ^favicon.ico|(?:(?:plugin_assets/|themes/).+/)(?:.+\.html|javascripts/.+\.js|stylesheets/.+\.css|images/.+\.(?:jpe?g|gif|ico|png))$ {

Which Etienne suggested in:

#13564

(1-3/3)