intercity / chef-repo

Set up your server to host Ruby on Rails apps. - Follow us on Twitter: @intercityup
MIT License
416 stars 82 forks source link

Configure nginx to server static gzipped content #72

Open yourivdlans opened 10 years ago

yourivdlans commented 10 years ago

At this time the nginx configuration does not include a config for serving static gzip content. See the rails guides for the actual config:

http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression

michiels commented 10 years ago

Thanks for pointing this out @yourivdlans! This will probably involve a bit more in the Chef recipes for the passenger stack because passenger takes care of serving assets as static files itself. To work around this, we probably need something like the following sample.

In this sample, we will try to load the URL first via try_files so it will use the location ~ ^/(assets)/ directive. If it can't find the file, it will try to run it from passenger.

server {
  ...
  root /u/apps/railsapp/current/public;
  try_files $uri @passenger;

  location @passenger {
    passenger_enabled on;
  }

  location ~ ^/(assets)/  {
    root /u/apps/railsapp/current/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }
  ...
}
jvanbaarsen commented 10 years ago

Looks like we also need to pass an option to Passenger when compiling with nginx From the rails docs:

If you're compiling nginx with Phusion Passenger you'll need to pass that option when prompted.

michiels commented 10 years ago

@jvanbaarsen We don't compile passenger or nginx. Passenger and nginx is installed form the Phusion deb repositories in the Rails cookbook.

jvanbaarsen commented 10 years ago

@michiels Ok, so that means we cant pass in the flag for gzip content? or is that passed in by default?

michiels commented 10 years ago

@jvanbaarsen It's passed by default. I don't think we need to change anything in how we install passenger itself for this issue.

jvanbaarsen commented 10 years ago

@michiels Ok thanks!