Add the attached script to the .ebextensions
folder in the deployment package to enable gzip compression on the nginx
proxy.
This compresses text payloads such as HTML, Javascript and JSON for a better client experience.
Works for Elastic Beanstalk with single-container Docker.
Some EB stacks allow the choice between Apache httpd
and nginx
so it will not for all EB configurations.
Last active
November 6, 2020 03:29
-
-
Save mjul/e0f73d159c71e4fce13c645a2f83344c to your computer and use it in GitHub Desktop.
Enable gzip compression in Elastic Beanstalk Docker nginx proxy (add to .ebextensions folder)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files: | |
"/etc/nginx/conf.d/gzip.conf": | |
mode: "644" | |
owner: "root" | |
group: "root" | |
content: | | |
# enable gzip compression | |
gzip on; | |
gzip_min_length 1100; | |
gzip_buffers 4 32k; | |
gzip_types text/plain text/html text/xml text/css application/javascript application/json; | |
gzip_vary on; | |
# end gzip configuration | |
container_commands: | |
02_restart_nginx: | |
command: service nginx restart |
It seems like on line 11, the text/html is not needed as it is compressed by default, and nginx will give warnings for duplication and it stops deployment.
I fixed my issues with this config:
https://gist.github.com/omidfi/aaae08617729d26fce52024cafb59e12
Looks like Elasticbeanstalk now has gzip enabled by default:
/etc/nginx/sites-available/elasticbeanstalk-nginx-docker-proxy.conf
map $http_upgrade $connection_upgrade {
default "upgrade";
"" "";
}
server {
listen 80;
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
access_log /var/log/nginx/access.log;
location / {
proxy_pass http://docker;
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I still couldn't get this to work, I got this:
And then in eb-activity log
I'm inspecting it more tomorrow