If your DirectAdmin server is delivering uncompressed HTML, CSS, and JavaScript to browsers, you're adding hundreds of milliseconds to every page load for every visitor. Compression reduces the size of text-based assets by 30–70%, cuts bandwidth costs, and directly improves Google Core Web Vitals scores — particularly Largest Contentful Paint (LCP) and Time to First Byte (TTFB).
DirectAdmin servers use Apache (managed via CustomBuild), Nginx (as a reverse proxy or standalone), or both in a combined stack. This guide covers enabling both Gzip and Brotli compression for each configuration.
Gzip vs Brotli: Which Should You Use?
- Gzip — supported by all browsers and all server stacks; typical compression ratio of 60–70% for HTML/CSS/JS; very low CPU overhead.
- Brotli — supported by all modern browsers (Chrome, Firefox, Safari, Edge); typical compression ratio of 70–80% (Brotli compresses HTML ~21% smaller than Gzip, JS ~14% smaller); requires HTTPS (Brotli is only served over HTTPS by design); slightly higher CPU overhead at high compression levels.
The best approach is to enable both: Brotli for clients that support it (served with Accept-Encoding: br), and Gzip as the fallback. Nginx and Apache will select the best encoding based on the browser's request headers automatically.
💡 None of these worked? Skip the guesswork.
Get Expert Help →Step 1: Enable Gzip Compression in Nginx (DirectAdmin)
On DirectAdmin servers with Nginx configured as a standalone server or reverse proxy, Gzip is typically available but disabled or minimally configured by default.
nano /etc/nginx/nginx.conf
http {} blockhttp {
# Gzip compression
gzip on;
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
text/plain
text/css
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
application/atom+xml
image/svg+xml
font/ttf
font/otf
font/woff
font/woff2;
}
Key settings explained:
gzip_comp_level 6: good balance between compression ratio and CPU usage (range 1–9; 6 is the standard recommendation)gzip_vary on: adds theVary: Accept-Encodingheader so CDNs and proxies cache both compressed and uncompressed versionsgzip_min_length 256: skips compression for very small files where the overhead isn't worthwhile
nginx -t && systemctl reload nginx
httpd -M 2>/dev/null | grep deflate
# or:
apachectl -M 2>/dev/null | grep deflate
# Expected output: deflate_module (shared)
If it's not listed, enable it via CustomBuild:
cd /usr/local/directadmin/custombuild
./build set deflate yes
./build apache
Create or edit /etc/httpd/conf.d/deflate.conf (AlmaLinux/RHEL) or /etc/apache2/conf-enabled/deflate.conf (Ubuntu/Debian):
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/css text/javascript
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/json application/xml
AddOutputFilterByType DEFLATE application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE font/ttf font/otf font/woff font/woff2
# Don't compress already-compressed formats
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|mp4)$ no-gzip dont-vary
# Add Vary header for correct CDN caching
Header append Vary Accept-Encoding
</IfModule>
systemctl restart httpd # AlmaLinux/RHEL
# or:
systemctl restart apache2 # Ubuntu/Debian
Step 4: Enable Brotli in Apache (DirectAdmin CustomBuild)
Apache 2.4.26+ supports mod_brotli. On DirectAdmin with CustomBuild, you can compile it in:
cd /usr/local/directadmin/custombuild
./build set brotli yes
./build apache
Then add the Brotli configuration alongside mod_deflate:
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml
AddOutputFilterByType BROTLI_COMPRESS text/css text/javascript
AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json
AddOutputFilterByType BROTLI_COMPRESS application/xml application/rss+xml
AddOutputFilterByType BROTLI_COMPRESS image/svg+xml font/woff font/woff2
BrotliCompressionQuality 5
</IfModule>
Restart Apache after the change.
Step 5: Test That Compression Is Working
Always verify that compression is actually being applied — misconfigured MIME types or module load order can silently prevent it.
Test with curl from the server:
# Test Gzip
curl -H "Accept-Encoding: gzip" -I https://yourdomain.com/
# Look for: Content-Encoding: gzip in response headers
# Test Brotli
curl -H "Accept-Encoding: br" -I https://yourdomain.com/
# Look for: Content-Encoding: br in response headers
Test a specific CSS or JS file:
curl -H "Accept-Encoding: br,gzip" -s -o /dev/null -w "%{size_download} %{content_type}
" -D - https://yourdomain.com/wp-content/themes/yourtheme/style.css | grep -E "Content-Encoding|Content-Length"
Online tools:
- GIDNetwork Compression Test — enter your URL and it reports whether Gzip/Brotli is active and the compression ratio
- Google PageSpeed Insights — flags "Enable text compression" if assets are uncompressed
- GTmetrix — shows compression status per asset under the Waterfall tab
Per-Domain and Per-Directory Configuration via .htaccess
If you want to enable compression only for specific domains without modifying the global server config, add this to the domain's .htaccess file:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json
Header append Vary Accept-Encoding
</IfModule>
Note: .htaccess-based compression only works for Apache. Nginx ignores .htaccess files — use the nginx.conf approach for Nginx vhosts.
Expected Performance Improvement
- HTML files: 60–80% smaller (a 100 KB page becomes 20–40 KB)
- CSS files: 50–70% smaller
- JavaScript files: 50–65% smaller with Gzip; 60–70% with Brotli
- JSON API responses: 60–80% smaller
For a typical WordPress site, enabling compression reduces total page weight from 500 KB to under 200 KB, cutting LCP times by 200–400ms on average connections. This can lift Google PageSpeed scores by 10–20 points.
If you're managing multiple DirectAdmin servers and want compression tuned correctly across every domain and stack, CloudHouse's managed server service handles Nginx and Apache performance configuration — including compression, caching, and HTTP/2 — as part of our ongoing server management plans.
