Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any reason Gzip is commented out in nginx config? #127

Open
redroot opened this issue Oct 28, 2015 · 16 comments

Comments

@redroot
Copy link

commented Oct 28, 2015

I'm looking to serve static assets with compression on a PHP site via nGinx, and I noticed that the gzip: on setting is commented out, any particular reason for this? I can't find any comments online or anything via git blame.

Any help would be appreciated, thanks in advance

@holtkamp

This comment has been minimized.

Copy link

commented Feb 11, 2016

+1 on this,

we've seen a significant increase in transfered content after migrating to Heroku from a server that did have GZip enabled yesterday 10-02-2016:
screen shot 2016-02-11 at 09 40 26

screen shot 2016-02-11 at 09 40 48

PS, yeah we know, still got to reduce the overall amount of transferred content like scripts, but that is a different issue ;)

@stof

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2016

@dzuelke any comment on this ?

@dzuelke

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2016

Is it a problem to enable it in the custom config that 99% of Nginx users on Heroku need anyway? :)

@dzuelke

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2016

(it's not enabled in Apache either)

@holtkamp

This comment has been minimized.

Copy link

commented Mar 29, 2016

In case it is not enabled by default, it might be useful to extend the current documentation a bit? Maybe with examples?

On the otherhand, it might save Heroku considerable amount of data transfer by enabling it by default, so why not enable it? And it is 2016, right? 😄

@dzuelke

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2016

Like those docs say, it's the responsibility of each application (and those docs are language agnostic, so no PHP specific stuff will go in there). So the normal Nginx or Apache configuration for compression applies.

Right now I see many customers only compressing JS/CSS/images, not page content. What would the default be? gzip_vary on;? What level? gzip_disable or not? Are all customers fine with gzip_proxied any? Will existing gzip setups break?

The defaults in Nginx are not enough. I can't just throw gzip on; into the default config; you need to set a whole bunch of directives...

@holtkamp

This comment has been minimized.

Copy link

commented Mar 29, 2016

ok, guess that would be a justified reason as was requested by @redroot then...

@dzuelke

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2016

Yeah :) I'm leaving this open as a reminder; not saying we can't do it by default, but it needs to be done carefully. I should have bandwidth to tackle this in a few weeks.

@hekaldama

This comment has been minimized.

Copy link

commented Sep 19, 2016

I am looking to have a solution for this as well. Maybe I have missed it or am new to this, but can I just specify my own nginx.conf?

@kbond

This comment has been minimized.

Copy link

commented Sep 20, 2016

@hekaldama you can in your Procfile:

web: vendor/bin/heroku-php-nginx -C etc/heroku/nginx.conf web/

In your nginx.conf:

gzip on;

# ...
@dwightwatson

This comment has been minimized.

Copy link

commented Jun 30, 2017

That didn't appear to work for me.

I still find it a little weird that gzip isn't enabled by default for both Apache and nginx.

Are you open to changing that default?

@HillLiu

This comment has been minimized.

Copy link

commented Sep 13, 2017

@dzuelke

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2017

The minimum config you need:

gzip         on;
gzip_vary    on;
gzip_proxied any;
gzip_types   …;
@cenobitedk

This comment has been minimized.

Copy link

commented Oct 6, 2017

Is there some magic trick to make this work?

Been trying to get gzip working with Apache with no success. Then I tried nginx and it doesn't work either. I can't figure why.

I added this from @HillLiu's comment above:

location / {
  gzip              on;
  gzip_vary         on;
  gzip_proxied      any;
  gzip_min_length   1k;
  gzip_buffers      16 8k;
  gzip_http_version 1.1;
  gzip_comp_level   9;
  gzip_types        text/plain
                    text/javascript
                    text/css
                    text/xml
                    application/json
                    application/javascript
                    application/atom+xml
                    application/rss+xml
                    application/x-javascript
                    application/xml
                    application/xhtml+xml
                    application/x-font-ttf
                    image/svg+xml
                    ;
}

This is my repo: https://github.com/cenobitedk/aphasia-site
Deployed here: http://beta.aphasia-records.com/

@HillLiu

This comment has been minimized.

Copy link

commented Oct 7, 2017

@cenobitedk Some case it affect by try_files and let it not apply " location / {} "

you have two options,

  1. move gzip outside location.
  2. use try_files fallback, and move gzip to fallback section.

About fallback you could refer.

location @heroku-fcgi {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# try_files resets $fastcgi_path_info, see http://trac.nginx.org/nginx/ticket/321, so we use the if instead
fastcgi_param PATH_INFO $fastcgi_path_info if_not_empty;
if (!-f $document_root$fastcgi_script_name) {
# check if the script exists
# otherwise, /foo.jpg/bar.php would get passed to FPM, which wouldn't run it as it's not in the list of allowed extensions, but this check is a good idea anyway, just in case
return 404;
}
fastcgi_pass heroku-fcgi;
}

If you just want rewrite to index.php
You could check what I write.
https://github.com/pmvc/heroku-config/blob/master/nginx_app.conf#L24-L26

And add
location ~ ^/index.php/ {
{
gzip xxx
}

It should also work.

@cenobitedk

This comment has been minimized.

Copy link

commented Oct 7, 2017

Thank you @HillLiu!

Option 1 seemed to do the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.