CloudLinux.ro
Web servers

How to optimize Nginx performance: gzip, cache and HTTP/2

Updated 7/20/2026

Nginx is already fast, but a few simple settings make it faster and cut bandwidth usage.

1. Gzip compression

In /etc/nginx/nginx.conf, inside the http block:

gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_min_length 256;

2. Cache static files

Tell browsers to keep images, CSS and JS locally:

location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
    expires 30d;
    add_header Cache-Control "public";
}

3. Enable HTTP/2

In the HTTPS server block:

listen 443 ssl http2;

4. Reload and test

nginx -t && systemctl reload nginx

When settings are not enough

If the server is already optimized but still overloaded, you need more resources. With hourly billing you can move to a bigger plan in minutes, without reinstalling.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials