Static files shown as uncompressed even if the web server is configured to gzip compression

I hosted my site on Amazon Elastic BeanStalk. It uses nginx as a proxy and has gzip compression. But when I run PageInsights on the site, it reports that many of my static content files must be gzipped. Why doesn't PageSpeed โ€‹โ€‹Insights recognize compression? Is there anything more that needs to be done?

+6
source share
3 answers

I think I found the answer

By enabling gzip compression on nginx, you enable it only for text / html (this is nginx by default http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types )

To enable it for other types, you must do this explicitly. If you create a beanstalk, create the following file in your project

.ebextensions / gzip.config

and put the code there (make sure you keep the indentation, this is important):

files: /etc/nginx/conf.d/gzip.conf: content: | gzip_types application/json; 

As you can see, in my case I needed gzip json files, you probably had problems with Pagespeed complaining about css and js files, right? As you can see from the link above, you can use the wildcard character * to compress everything, but if not, just list the mime types that you need in the configuration, expand them and check the PageSpeed โ€‹โ€‹properties again.

+5
source

Dmitry answers only if there is no gzip_types entry in the default setting for Amazon. This is the case now, and you will need to write a conf.ebextensions file to overwrite the entire configuration using a special one. For this you need:

  • Download the default configuration from one of your instances via SSH. It will be located in the /etc/nginx/conf.d folder and will be called 00_elastic_beanstalk_proxy.conf
  • Create a new file in your .ebextensions folder called proxy.conf , which follows this template:

     files: "/etc/nginx/conf.d/proxy.conf": mode: "000644" owner: root group: root content: | # Paste the contents of the config you downloaded here # at this indentation level container_commands: 00_remove: command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf" 
  • Change the configuration to have the necessary gzip_types.
  • Expand Application

For reference, this is my working proxy.conf file as follows: https://pastebin.com/raw/KGvdsZc4

A word of caution: I was sure that it was a common use case to rewrite the entire configuration in this way, and although it would facilitate a configuration change in the future, it would disrupt some of the features of AWS EB Web Tools. In particular, nothing that affects the nginx configuration (static file paths, gzip compression, etc.) will not work. To make changes, you just need to change the configuration directly in proxy.conf

0
source
Decision

techwes was very useful and worked fine (in my case, I allowed to add the application / javascript to gzip_types) with one modification: the file in the .ebextensions folder should be named with the extension .config , so it should be proxy.config . (I tried adding a comment to the Techwes post, but not enough reputation!)

It should also be noted that if you disable gzip in EB using the AWS console (Environment> Configuration> Software Configuration), it will remove the gzip lines from 00_elastic_beanstalk_proxy.conf , so you can use .config to add another .conf file without the need to replace the entire 00_elastic_beanstalk_proxy.conf file.

0
source

All Articles