brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx gzip_types is the line that makes JSON and CSS compress

Nginx
~/tips/tip-nginx-gzip-types-line

gzip on;

Compresses CSS, JavaScript and JSON responses, which nginx skips by default.

Turning gzip on is only half of it, because the default list of compressed types is very short.

gzip on;
gzip_vary on;
gzip_types text/css application/javascript application/json image/svg+xml;

gzip on compresses text/html only. gzip_types adds the other types, and listing text/html again is not needed. gzip_vary on adds Vary: Accept-Encoding so shared caches keep a plain and a compressed copy. Leave JPEG, PNG, MP4 and archives out, since they are already compressed. Check the result with curl -sI -H 'Accept-Encoding: gzip' https://example.com/app.css and look for Content-Encoding: gzip. The default gzip_comp_level is 1, and a value around 5 is a fair trade of CPU for size on text.

Further reading: ngx_http_gzip_module

Going deeper: 🛜 Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link