Docs / Web Servers / How to Enable Gzip Compression in Nginx

How to Enable Gzip Compression in Nginx

By Admin · Feb 25, 2026 · Updated Apr 25, 2026 · 510 views · 1 min read

Gzip compression reduces response sizes by 60-80%, improving page load times.

Enable in nginx.conf

Edit /etc/nginx/nginx.conf and add inside the http block:

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
    text/plain
    text/css
    text/javascript
    application/javascript
    application/json
    application/xml
    image/svg+xml
    font/woff2;

Test

nginx -t
systemctl reload nginx

Verify

curl -H "Accept-Encoding: gzip" -I https://example.com

Look for Content-Encoding: gzip in the response headers.

Was this article helpful?