Website performance is critical for both user experience and search engine ranking. One key factor affecting performance is the size of the files that browsers must download. Reducing file sizes speeds up loading times and reduces bandwidth usage. In this blog we’ll learn How to Improve Website Performance with gzip and Nginx on Ubuntu
Introduction
gzip is a popular data compression method that can significantly reduce the size of web files. Nginx can be configured to compress files on the fly, sending compressed data to browsers that automatically decompress it. This process is lossless, meaning no information is lost, just smaller data transfers.
Text-based files like HTML, CSS, and JavaScript compress extremely well, sometimes shrinking to less than half their original size. On the other hand, images like JPEG or PNG are already compressed, so additional compression has minimal effect.
Prerequisites
Before starting, ensure you have:
- An Ubuntu server with a non-root user with sudo privileges.
- Nginx installed on your server.
Step 1 — Creating Test Files
To see gzip in action, we’ll create a few small test files in Nginx’s default directory:
sudo truncate -s 1k /var/www/html/test.html
sudo truncate -s 1k /var/www/html/test.jpg
sudo truncate -s 1k /var/www/html/test.css
sudo truncate -s 1k /var/www/html/test.js
Nginx determines file type via the file extension, so the actual content of these files is irrelevant.
Step 2 — Checking the Default Behavior
We can check if Nginx compresses files by sending an HTTP request with gzip support:
curl -H "Accept-Encoding: gzip" -I http://localhost/test.html
Expected output for HTML:

By default, Nginx compresses only HTML files. Other file types like CSS, JS and images are served uncompressed:
curl -H "Accept-Encoding: gzip" -I http://localhost/test.css
Output: no Content-Encoding header
Step 3 — Configuring gzip in Nginx
Open the Nginx configuration file:
sudo nano /etc/nginx/nginx.conf
Locate the gzip section. You’ll see something like this:
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Update it to enable additional compression options and extend gzip to more file types:
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
Save the file and restart Nginx:
sudo systemctl restart nginx
Step 4 — Verifying gzip Compression
Check the HTML file again:
curl -H "Accept-Encoding: gzip" -I http://localhost/test.html
You should see:

Check CSS or JavaScript files:
curl -H "Accept-Encoding: gzip" -I http://localhost/test.css
Now gzip is active for these file types too.

Conclusion
Enabling gzip compression in Nginx is simple but highly effective. Benefits include:
- Faster load times for users on limited bandwidth.
- Reduced server bandwidth usage.
- Improved SEO with faster page speed.
By extending gzip to all compressible file types, you optimize your website’s performance with minimal effort.
If you’re looking to Improve Website Performance with gzip and Nginx on Ubuntu, implementing the right configuration is only the first step. Consistent monitoring, fine-tuning, and expert-level server management are essential to ensure long-term speed, security, and stability. Our team specializes in Web Server Optimization Services, offering complete support for Nginx, Apache, and Ubuntu-based environments. Whether you need help enabling gzip compression, optimizing your server for peak performance, or resolving configuration issues, our experts are available 24/7 to assist.