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 pricingRelated tutorials
How to install phpMyAdmin to manage MySQL from the browser
Manage your MySQL databases from a web interface with phpMyAdmin, installed and secured correctly.
Updated 7/20/2026Web serversHow to deploy a Laravel app to production
Deploy Laravel properly on a VPS: Nginx, PHP-FPM, permissions, optimizations and the queue worker.
Updated 7/20/2026Web serversHow to host a static site or a React/Vue app
Publish a static site or a React/Vue build on Nginx, with correct routing for single-page apps.
Updated 7/20/2026