Web Servers (Apache, Nginx, Caddy)

Optimizing Gzip and Brotli Compression on VPS with EA-Nginx: The Complete Admin Guide for CloudLinux + cPanel Servers

By the Domain India teamPublished 8 min read
Knowledge base article
Contents (9 sections)

cPanel's ea-nginx puts nginx in front of Apache as a reverse proxy and cache. That changes where compression has to happen: rules in Apache or .htaccess no longer control every response the visitor receives. This guide is for administrators of their own CloudLinux or AlmaLinux server running cPanel & WHM with ea-nginx. It shows how to check what is already compressed, enable gzip safely at the nginx layer, decide about Brotli, and verify and roll back the change.

Key takeaways

If your site is on Domain India shared hosting, there is nothing to do: our cPanel servers already gzip HTML, CSS, JavaScript, JSON, XML and SVG at the nginx layer. On your own cPanel server with ea-nginx, first check the existing configuration with nginx -T, because gzip may already be on and duplicate directives break the reload. Add gzip settings in one file under /etc/nginx/conf.d/, test with nginx -t, reload, clear the ea-nginx cache and check Content-Encoding with curl. Add Brotli only if your nginx build already ships the modules; otherwise let a CDN provide it.

1. On Domain India shared hosting: already done

You can't change nginx on shared hosting, and you don't need to. On our cPanel servers the nginx proxy compresses HTML, CSS, JavaScript, JSON, XML and SVG for every site; our DirectAdmin servers use Apache's mod_deflate server-wide. Our servers don't serve Brotli. To check your own site, follow How to enable gzip compression in cPanel.

Everything below is for a server you administer with root access.

2. Why Apache rules are not enough behind ea-nginx

With ea-nginx, every request reaches nginx first. Depending on your configuration, nginx passes it to Apache, answers from its proxy cache, or serves a static file directly. Apache's mod_deflate, whether set in WHM or in a customer's .htaccess, only affects responses Apache generates. Anything nginx serves from its cache or from disk skips it.

Compressing at the nginx layer covers all three paths with one setting, for every site on the server.

3. Check what you already have

Before changing anything, look at the full configuration nginx is running:

bash
nginx -T 2>/dev/null | grep -nE '^\s*(gzip|brotli)'
nginx -V 2>&1 | tr ' ' '\n' | grep -i brotli
ls /usr/lib64/nginx/modules/ 2>/dev/null | grep -i brotli
  • If gzip on; already appears in the http block, it is already enabled; current ea-nginx versions set it in the main nginx.conf. Adjust that setting rather than adding a second one: nginx rejects a directive that appears twice in the same block, and the reload fails.
  • If a gzip off; appears in a later include or a server block, it overrides your global setting for those sites.
  • If the last two commands print nothing, your nginx has no Brotli modules. See section 5.

Then check a real page and one real CSS file from a site on the server:

bash
curl -s -o /dev/null -D - -H 'Accept-Encoding: gzip, br' 'https://example.com/?t=1' | grep -iE '^(server|content-type|content-encoding|vary)'

4. Enable gzip at the nginx layer

Create one file for your settings, so they are easy to find and roll back. Files in /etc/nginx/conf.d/ ending in .conf are included in the http block:

nginx
# /etc/nginx/conf.d/zz-gzip.conf
gzip on;
gzip_comp_level 5;
gzip_min_length 512;
gzip_vary on;
gzip_proxied any;
gzip_types text/plain text/css text/xml text/javascript
           application/javascript application/json application/ld+json
           application/xml application/rss+xml application/atom+xml
           image/svg+xml font/ttf font/otf application/vnd.ms-fontobject;

Notes on the choices:

  • text/html is not listed because nginx always compresses it when gzip is on; listing it produces a duplicate-type warning.
  • Level 4 to 6 gives nearly all of the size saving at a fraction of the CPU cost of level 9.
  • gzip_proxied any makes nginx compress responses it proxies from Apache.
  • gzip_vary on adds Vary: Accept-Encoding, so caches and CDNs keep compressed and uncompressed copies apart.
  • Leave out images, WOFF2 fonts, video, PDF and archives. They are already compressed; gzip only costs CPU.

Test and reload:

bash
nginx -t && systemctl reload nginx

Never reload after a failed nginx -t. If the test complains about a duplicate directive, remove it from your file and use the existing one.

5. Brotli: only with modules you already have

Brotli compresses text slightly better than gzip, and every current browser supports it over HTTPS. On a cPanel server, though, nginx is a cPanel-managed package:

  • If section 3 showed Brotli modules (recent ea-nginx builds ship ngx_http_brotli_filter_module.so and ngx_http_brotli_static_module.so without loading them), load them at the top of /etc/nginx/nginx.conf with load_module lines, add brotli on;, a brotli_comp_level of 4 to 6 and a brotli_types list matching your gzip types, then test and reload.
  • If it didn't, don't compile third-party modules into the cPanel nginx. Package updates replace the binary, and a module built for the old version stops nginx from starting.

The simpler route to Brotli is a CDN in front of the server. Cloudflare, for example, compresses to Brotli for browsers that support it, whatever your server sends. See Cloudflare setup for Indian websites.

6. Clear the cache and verify

ea-nginx keeps cached responses made under the old settings. Clear the cache with cPanel's own tool rather than deleting cache directories by hand:

bash
/usr/local/cpanel/scripts/ea-nginx clear_cache --all

You can name one or more cPanel usernames instead of --all. Run /usr/local/cpanel/scripts/ea-nginx help to see the options on your version.

Then verify on real, existing files. A 404 page or an image tells you nothing:

bash
for u in 'https://example.com/?t=2' 'https://example.com/wp-includes/css/dist/block-library/style.min.css?t=2'; do
  echo "== $u"
  curl -s -o /dev/null -D - -H 'Accept-Encoding: gzip, br' "$u" | grep -iE '^(content-type|content-encoding|vary)'
done

You should see content-encoding: gzip (or br) and vary: Accept-Encoding. In a browser, open developer tools, tick "Disable cache" on the Network tab and read the response headers of the page, a CSS and a JavaScript file.

7. Roll back

Because everything lives in one file, rolling back is quick:

bash
mv /etc/nginx/conf.d/zz-gzip.conf /root/zz-gzip.conf.disabled
nginx -t && systemctl reload nginx

If you added Brotli load_module lines, remove those as well before the test. Keep an eye on CPU for a day after the change with top and on nginx errors with journalctl -u nginx -n 100 --no-pager; at level 5 the extra load is usually small.

8. Troubleshooting checklist

SymptomLikely causeFix
No content-encoding on any sitegzip off in a later include, or the reload failedSearch nginx -T for gzip off; run nginx -t and read the error
Compressed on one site, not anotherA server block for that site sets its own gzipCheck that site's include files
Compressed with curl, not in the browserThe browser shows a cached copy, or a CDN changes the responseTick Disable cache; check the CDN's compression setting
Brotli expected, gzip receivedNo Brotli modules, or the test was over plain HTTPBrotli is used over HTTPS; see section 5
Double-compressed garbage in the browserThe application compresses too, and a proxy compresses againTurn off compression in the application or plugin

9. Where Domain India fits

If you'd rather not manage nginx at all, Domain India cPanel hosting has compression already set up at the nginx layer, with free SSL and weekly JetBackup backups. See cPanel hosting. Domain India VPS plans are self-managed and don't include cPanel; the panel options offered at checkout are listed on the VPS page. On a VPS without cPanel you configure nginx directly, and the gzip settings in section 4 apply as they are.

cPanel Starter
₹125/mo + GST
  • 25 GB NVMe SSD Storage
  • 50 GB Monthly Bandwidth
  • 1 Website
  • 10 Email Accounts
See plan details

Prices on the cards exclude 18% GST.

Do I need to enable gzip on Domain India shared hosting?

No. Our cPanel servers compress HTML, CSS, JavaScript, JSON, XML and SVG at the nginx layer for every site, and our DirectAdmin servers use Apache mod_deflate server-wide.

Why doesn't my .htaccess compression work behind ea-nginx?

Apache rules only affect responses Apache generates. With ea-nginx, nginx may serve a response from its cache or a static file from disk without Apache, so compression has to be set at the nginx layer.

Where do I put gzip settings for ea-nginx?

In one .conf file under /etc/nginx/conf.d/, which is included in the http block. Check nginx -T first, because gzip may already be on and a duplicate directive makes the reload fail.

Can I add Brotli to cPanel's nginx?

Only if your nginx build already includes the Brotli modules. Don't compile third-party modules into the cPanel-managed nginx, because updates replace the binary. A CDN such as Cloudflare can serve Brotli instead.

What gzip compression level should I use?

A level between 4 and 6. It gives almost all of the size saving of level 9 for much less CPU.

Should I compress images and WOFF2 fonts?

No. They are already compressed, so gzip or Brotli only adds CPU work without making them smaller.

Ready to speed up your sites? Check a shared hosting site with How to enable gzip compression in cPanel, work through My website is slow, or open a support ticket if pages on our servers arrive uncompressed.

Hosting with compression already on

Domain India cPanel hosting compresses every site at the nginx layer, with free SSL and weekly backups.

Compare cPanel hosting

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
Gzip & Brotli on cPanel ea-nginx: Enable, Verify, Roll Back