3

I have an AWS EB environment of Python 3.7 running Amazon Linux 2/3.1.2 using Nginx as a proxy server. I'm trying to add a gzip compression for my application. I tried out several tutorials online but they all don't appear to work for me. I'm also new to AWS so might not be familiar with some of its services.

Currently, I had a directory tree like this:

-- .ebextensions
-- .platform
   -- nginx
     -- conf.d
        -- gzip.conf
-- (other files)

I tried adding a config file in .ebextensions to create a .conf to enable gzip compression, but it didn't seem to work. I also tried switching the proxy to Apache, but no luck. This tutorial says that for the latest version of Amazon Linux 2, the nginx config files should be placed in the .platform folder, so I did as noted. However, my gzip.conf file still didn't seem to work - files are still rendered in their original formats.

Currently my gzip.conf:

gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/html text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

EDIT: I SSH'd into my eb instance and found this file is at /etc/nginx/conf.d/gzip.conf and the content is the same as what I uploaded. Would this path be correct to enable gzip?

Any help will be appreciated!

Parzival
  • 1,666
  • 3
  • 9
  • 25
  • 1
    If you ssh into the EB instance, can you manually setup nginx to make it work? This way you can at least confirm the options you want to use. – Marcin Jan 19 '21 at 09:59
  • I ran into similar issues and wrote a gist summarizing how to change nginx configurations for Amazon Linux 2. You can find it here: https://gist.github.com/henhan/2943013c9064606425b0ee5bb1ca8c99 – Henrik Hansson Aug 01 '21 at 11:26

1 Answers1

4

After searching online for guides to use SSH in AWS, I was able to ssh into my EB instance and found that the problem was in the file /etc/nginx/nginx.conf, which includes the default setting gzip off. For some reason my extension of this file did not overwrite this setting.

Thanks to @Marcin's suggestion to set up in SSH. I obtained a copy of nginx.conf and added it to my project directory .platform/nginx, commented out the original settings for gzip, and updated it into the following:

#Original Settings
#gzip                  off;
#gzip_comp_level       4;
#gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

#New Settings
gzip on;
gzip_static on;
gzip_comp_level 9;
gzip_proxied any;
gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml application/json font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/html text/javascript text/plain text/xml;

After deploying, it finally worked! Hope this would help others who had the same question.

Parzival
  • 1,666
  • 3
  • 9
  • 25
  • 3
    You should never touch anything on ElasticBeanstalk instances. Those instances are continuously going up and down due to the scaling and the config file changes will be lost. You should do this with .ebextentions – Peter May 04 '21 at 16:44