chef-repo icon indicating copy to clipboard operation
chef-repo copied to clipboard

Configure nginx to server static gzipped content

Open yourivdlans opened this issue 10 years ago • 6 comments

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

yourivdlans avatar Jul 23 '14 09:07 yourivdlans

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;
  }
  ...
}

michiels avatar Jul 31 '14 11:07 michiels

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.

jvanbaarsen avatar Sep 15 '14 07:09 jvanbaarsen

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

michiels avatar Sep 15 '14 09:09 michiels

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

jvanbaarsen avatar Sep 15 '14 09:09 jvanbaarsen

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

michiels avatar Sep 15 '14 09:09 michiels

@michiels Ok thanks!

jvanbaarsen avatar Sep 15 '14 09:09 jvanbaarsen