Configuring nginx to gzip static files

April 08, 2021


When using dokku the static files (css, js, etc..) are typically served by nginx but by default nginx only gzip's html files. It's simple to change that, here's how.


Edit the /etc/nginx/nginx.conf file and find the gzip section. gzip is on by default and the lines are already there, so just uncomment the following lines:


# Find and uncomment the following (adjust as needed)
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/html text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;


There's more options that can be adjusted as needed. See the docs on the ngx_http_gzip_module for more details.


This simple change saved about 300kb for this site! Thank you to the nginx devs for making this so simple!


Cheers!