ryandotsmith / nginx-buildpack

Run NGINX in front of your app server on Heroku
457 stars 248 forks source link

GZip Assets #24

Open paynecodes opened 10 years ago

paynecodes commented 10 years ago

I came across this buildpack mostly due the fact that I wanted to GZip my assets. I figured nginx would be good for this (as well as the reasons listed in your README).

Anyways, I added the default nginx.conf.erb to my config folder. Then I attempted adding the following from the Asset Pipeline Guide to the server section like this:

server {
  ...
  location ~ ^/(assets)/  {
    root /path/to/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }
}

I get an application error. Here's the most important part from the logs:

nginx: [emerg] unknown directive "gzip_static" in ./config/nginx.conf

Of course, /path/to/public is just placeholder, so, as a side note, I'm wondering if this will work:

root <%= Rails.root.join('public').to_s %>

Moving forward, it seems that nginx needs to be configured with http_gzip_static_module. I'm not exactly sure how to do that or if it fits in the scope of this repo.

Does anyone have any experience with trying to GZip precompiled assets using nginx? Better way? Am I on to something we could merge in with this repo? This module seems to be configurable in other, less popular build packs I've seen around here on GitHub.

Also, this method is documented here using Passenger: http://dennisreimann.de/blog/configuring-nginx-for-the-asset-pipeline/

diwu1989 commented 10 years ago

I had to set the following rules:

http {
        gzip on;
        gzip_comp_level 2;
        gzip_proxied any;
        gzip_min_length 512;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml image/svg+xml;
khoan commented 9 years ago

looks like --with-http_gzip_static_module wasn't included when compiling nginx binary (see http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html)