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!
3
Answers
Big idea: To gain full control of your nginx configurations, you need to override the default settings in the
.platform/nginx/nginx.conf
file in your project directory.The problem: When I ssh'd into my EB instance, I found that in the file
/etc/nginx/nginx.conf
still includes the default settinggzip off
. For some reason my extension of this file did not overwrite this setting. I suppose it's because in Amazon Linux 2, the proxy configurations should be under.platform/nginx
directory.Solution: I used ssh to obtain a copy of
nginx.conf
, added it to my project directory.platform/nginx
, commented out the original settings for gzip, and added the new gzip settings. Below is a snippet of my updatednginx.conf
file:After deploying, it finally worked! Hope this will help others with the same question.
Thanks to @Marcin's suggestion to ssh into my instance, which helped me figure out what's going on.
An alternative solution to @Parzival ‘s,
instead of overwriting the root nginx config, you can overwrite the app config file.
To get the application configuration file, ssh into the instance and get the configuration file from:
/etc/nginx/conf.d/elasticbeanstalk/00_application.conf
Mine looked like this:
Saved it into my project at:
.platform/nginx/conf.d/elasticbeanstalk/00_application.conf
And edited it adding what I need:
After that, create a new bundle and deploy it. Beanstalk will use your custom
00_application.conf
instead of the default one.Notes:
gzip_types
settingtext/*
, the default config in the root file was:I fixed this issue with a small script that I left on
.platform/hooks/predeploy
.Code snippet below.