ServerHandbook live check: run log ------------------------------------------------------------------------------ Check scripts/live/checks/nginx-gzip-brotli-ubuntu.mjs (sha256 a53b6179757f13710c2b1d2f885787c1d287403d8fdf13ac009d18a3afb80abd) Ran at 2026-11-18T06:36:45Z (81 s) Result PASS, all 28 claims held Tested on System Ubuntu 24.04.5 LTS Kernel 6.8.0-147-generic Package nginx 1.24.0-2ubuntu7.19 Package libnginx-mod-http-brotli-filter 1.0.0~rc-5build1 Package curl 8.5.0-2ubuntu10.16 Setup A fresh Ubuntu 24.04 server from Ubuntu’s cloud image, with ufw on and Nginx installed as the earlier articles leave it, serving the default site plus a real 72 KB stylesheet and a real 37 KB minified script from open-source projects; reached over SSH as a sudo user. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (1) libnginx-mod-http-brotli-filter 1.0.0~rc-5build1 Packages upgraded (0) Packages removed (0) Services enabled at boot (0) Services disabled (0) Listening sockets opened (0) Listening sockets closed (0) Files added in /etc (3) /etc/nginx/conf.d/brotli.conf /etc/nginx/conf.d/compression.conf /etc/nginx/modules-enabled/50-mod-http-brotli-filter.conf Files changed in /etc (0) Files removed from /etc (0) Disk used on / (includes logs written during the run): +0.1 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Claims (28), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) Nginx serves the default site with a real stylesheet and a real minified script, byte for byte | 72074 | 36731 3. ok nginx.conf already says "gzip on;", and the other gzip lines are commented out | 46: gzip on; | 48: # gzip_vary on; | 49: # gzip_proxied any; | 50: # gzip_comp_level 6; | 51: # gzip_buffers 16 8k; | 52: # gzip_http_version 1.1; | 53: # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 4. ok the HTML page comes back gzip, but style.css and app.js do NOT (gzip_types defaults to text/html) | index.nginx-debian.html 397 bytes gzip | style.css 72074 bytes | app.js 36731 bytes 5. ok nginx -t fails: "gzip" directive is duplicate in /etc/nginx/conf.d/compression.conf:1 | 2026/11/18 06:37:47 [emerg] 3272#3272: "gzip" directive is duplicate in /etc/nginx/conf.d/compression.conf:1 | nginx: configuration file /etc/nginx/nginx.conf test failed 6. ok compression.conf is written again (tee prints nothing with > /dev/null) 7. ok nginx -t is successful | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 8. ok now all three come back gzip, and the CSS and JS are much smaller | index.nginx-debian.html 394 bytes gzip | style.css 16548 bytes gzip | app.js 9468 bytes gzip 9. ok the response says Content-Encoding: gzip and Vary: Accept-Encoding | Content-Type: text/css | Vary: Accept-Encoding | Content-Encoding: gzip 10. ok a client that does not ask for gzip gets the plain file (Content-Length, no Content-Encoding) | Content-Length: 72074 11. ok with a Via header (the request came through a proxy) style.css is NOT compressed: gzip_proxied is off | 72074 bytes 12. ok nginx -t is successful with gzip_proxied any | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 13. ok with gzip_proxied any, the proxied request is compressed too | 16548 bytes gzip 14. ok Ubuntu 24.04 has the Brotli module as a package (universe) | libnginx-mod-http-brotli-filter: | Installed: (none) | Candidate: 1.0.0~rc-5build1 | Version table: | 1.0.0~rc-5build1 500 | 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages 15. ok apt installs the Brotli filter module | Reading package lists... Done | Building dependency tree... Done | Reading state information... Done | The following NEW packages will be installed: | libnginx-mod-http-brotli-filter | 0 upgraded, 1 newly installed, 0 to remove and 50 not upgraded. | Need to get 9346 B of archives. | After this operation, 43.0 kB of additional disk space will be used. | Get:1 http://archive.ubuntu.com/ubuntu noble/universe amd64 libnginx-mod-http-brotli-filter amd64 1.0.0~rc-5build1 [9346 B] | Fetched 9346 B in 0s (25.9 kB/s) | | Selecting previously unselected package libnginx-mod-http-brotli-filter. | (Reading database ... 75120 files and directories currently installed.) | Preparing to unpack .../libnginx-mod-http-brotli-filter_1.0.0~rc-5build1_amd64.deb ... | Unpacking libnginx-mod-http-brotli-filter (1.0.0~rc-5build1) ... | Setting up libnginx-mod-http-brotli-filter (1.0.0~rc-5build1) ... | Processing triggers for nginx (1.24.0-2ubuntu7.19) ... | Triggering nginx reload ... | | Scanning processes... | Scanning linux images... | | Running kernel seems to be up-to-date. | | No services need to be restarted. | | No containers need to be restarted. | | No user sessions are running outdated binaries. | | No VM guests are running outdated hypervisor (qemu) binaries on this host. 16. ok the package turned the modules on itself (modules-enabled holds a brotli file) | 50-mod-http-brotli-filter.conf 17. ok nginx -t is successful with brotli.conf | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 18. ok asking for br: all three come back br, smaller than gzip | index.nginx-debian.html 305 bytes br | style.css 15829 bytes br | app.js 8972 bytes br 19. ok a client that accepts "gzip, deflate, br" (as browsers do over HTTPS) gets br | index.nginx-debian.html 305 bytes br | style.css 15829 bytes br | app.js 8972 bytes br 20. ok (a stylesheet asked for with br comes back br) | Content-Encoding: br 21. ok (and with gzip, gzip) | Content-Encoding: gzip 22. ok (tested on) the box reports its OS, kernel and the version of 3 package(s) | PRETTY_NAME="Ubuntu 24.04.5 LTS" | VIRT=none | KERNEL=6.8.0-147-generic | PKG curl 8.5.0-2ubuntu10.16 | PKG libnginx-mod-http-brotli-filter 1.0.0~rc-5build1 | PKG nginx 1.24.0-2ubuntu7.19 23. ok apt removes the module, and its own reload of Nginx FAILS: "Job for nginx.service failed", action "reload" failed | Reading package lists... Done | Building dependency tree... Done | Reading state information... Done | The following packages will be REMOVED: | libnginx-mod-http-brotli-filter | 0 upgraded, 0 newly installed, 1 to remove and 50 not upgraded. | After this operation, 43.0 kB disk space will be freed. | | (Reading database ... 75128 files and directories currently installed.) | Removing libnginx-mod-http-brotli-filter (1.0.0~rc-5build1) ... | Processing triggers for nginx (1.24.0-2ubuntu7.19) ... | Triggering nginx reload ... | Job for nginx.service failed. | See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. | invoke-rc.d: initscript nginx, action "reload" failed. 24. ok nginx -t now fails: unknown directive "brotli" in /etc/nginx/conf.d/brotli.conf:1 | 2026/11/18 06:38:03 [emerg] 5101#5101: unknown directive "brotli" in /etc/nginx/conf.d/brotli.conf:1 | nginx: configuration file /etc/nginx/nginx.conf test failed 25. ok the site is still up: nginx keeps running on the config it loaded before | active 26. ok but a restart (or a reboot) fails, and the site is DOWN: "Job for nginx.service failed" | Job for nginx.service failed because the control process exited with error code. | See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. 27. ok with both files gone, nginx -t is successful and Nginx starts again | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 28. ok back to Ubuntu’s default: only the HTML page is gzip | index.nginx-debian.html 397 bytes gzip | style.css 72074 bytes | app.js 36731 bytes ------------------------------------------------------------------------------ Commands and what they printed (29) ------------------------------------------------------------------------------ $ grep -n gzip /etc/nginx/nginx.conf 46: gzip on; 48: # gzip_vary on; 49: # gzip_proxied any; 50: # gzip_comp_level 6; 51: # gzip_buffers 16 8k; 52: # gzip_http_version 1.1; 53: # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; $ for f in index.nginx-debian.html style.css app.js; do curl -s -o /dev/null -H 'Accept-Encoding: gzip' -w "$f %{size_download} bytes %header{content-encoding}\n" http://localhost/$f; done index.nginx-debian.html 397 bytes gzip style.css 72074 bytes app.js 36731 bytes $ sudo tee /etc/nginx/conf.d/compression.conf > /dev/null <<'EOF' $ gzip on; $ gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml; $ EOF $ sudo nginx -t 2026/11/18 06:37:47 [emerg] 3272#3272: "gzip" directive is duplicate in /etc/nginx/conf.d/compression.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed $ sudo tee /etc/nginx/conf.d/compression.conf > /dev/null <<'EOF' $ # gzip is already on in /etc/nginx/nginx.conf: do not repeat "gzip on;" here $ gzip_vary on; $ gzip_comp_level 6; $ gzip_min_length 256; $ gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml; $ EOF $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx $ for f in index.nginx-debian.html style.css app.js; do curl -s -o /dev/null -H 'Accept-Encoding: gzip' -w "$f %{size_download} bytes %header{content-encoding}\n" http://localhost/$f; done index.nginx-debian.html 394 bytes gzip style.css 16548 bytes gzip app.js 9468 bytes gzip $ curl -sI -H 'Accept-Encoding: gzip' http://localhost/style.css | grep -iE '^(content-type|content-encoding|vary)' Content-Type: text/css Vary: Accept-Encoding Content-Encoding: gzip $ curl -sI http://localhost/style.css | grep -iE '^(content-length|content-encoding)' Content-Length: 72074 $ curl -s -o /dev/null -H 'Accept-Encoding: gzip' -H 'Via: 1.1 proxy' -w "%{size_download} bytes %header{content-encoding}\n" http://localhost/style.css 72074 bytes $ echo 'gzip_proxied any;' | sudo tee -a /etc/nginx/conf.d/compression.conf gzip_proxied any; $ sudo nginx -t && sudo systemctl reload nginx nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ curl -s -o /dev/null -H 'Accept-Encoding: gzip' -H 'Via: 1.1 proxy' -w "%{size_download} bytes %header{content-encoding}\n" http://localhost/style.css 16548 bytes gzip $ apt-cache policy libnginx-mod-http-brotli-filter libnginx-mod-http-brotli-filter: Installed: (none) Candidate: 1.0.0~rc-5build1 Version table: 1.0.0~rc-5build1 500 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages $ sudo apt install -y libnginx-mod-http-brotli-filter Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: libnginx-mod-http-brotli-filter 0 upgraded, 1 newly installed, 0 to remove and 50 not upgraded. Need to get 9346 B of archives. After this operation, 43.0 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu noble/universe amd64 libnginx-mod-http-brotli-filter amd64 1.0.0~rc-5build1 [9346 B] Fetched 9346 B in 0s (25.9 kB/s) Selecting previously unselected package libnginx-mod-http-brotli-filter. (Reading database ... 75120 files and directories currently installed.) Preparing to unpack .../libnginx-mod-http-brotli-filter_1.0.0~rc-5build1_amd64.deb ... Unpacking libnginx-mod-http-brotli-filter (1.0.0~rc-5build1) ... Setting up libnginx-mod-http-brotli-filter (1.0.0~rc-5build1) ... Processing triggers for nginx (1.24.0-2ubuntu7.19) ... Triggering nginx reload ... Scanning processes... Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. $ ls /etc/nginx/modules-enabled/ 50-mod-http-brotli-filter.conf $ sudo tee /etc/nginx/conf.d/brotli.conf > /dev/null <<'EOF' $ brotli on; $ brotli_comp_level 6; $ brotli_min_length 256; $ brotli_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml; $ EOF $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx $ for f in index.nginx-debian.html style.css app.js; do curl -s -o /dev/null -H 'Accept-Encoding: br' -w "$f %{size_download} bytes %header{content-encoding}\n" http://localhost/$f; done index.nginx-debian.html 305 bytes br style.css 15829 bytes br app.js 8972 bytes br $ for f in index.nginx-debian.html style.css app.js; do curl -s -o /dev/null -H 'Accept-Encoding: gzip, deflate, br' -w "$f %{size_download} bytes %header{content-encoding}\n" http://localhost/$f; done index.nginx-debian.html 305 bytes br style.css 15829 bytes br app.js 8972 bytes br $ sudo apt remove -y libnginx-mod-http-brotli-filter Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: libnginx-mod-http-brotli-filter 0 upgraded, 0 newly installed, 1 to remove and 50 not upgraded. After this operation, 43.0 kB disk space will be freed. (Reading database ... 75128 files and directories currently installed.) Removing libnginx-mod-http-brotli-filter (1.0.0~rc-5build1) ... Processing triggers for nginx (1.24.0-2ubuntu7.19) ... Triggering nginx reload ... Job for nginx.service failed. See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. invoke-rc.d: initscript nginx, action "reload" failed. $ sudo nginx -t 2026/11/18 06:38:03 [emerg] 5101#5101: unknown directive "brotli" in /etc/nginx/conf.d/brotli.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed $ systemctl is-active nginx active $ sudo systemctl restart nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. $ sudo rm /etc/nginx/conf.d/brotli.conf /etc/nginx/conf.d/compression.conf $ sudo nginx -t && sudo systemctl start nginx nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ for f in index.nginx-debian.html style.css app.js; do curl -s -o /dev/null -H 'Accept-Encoding: gzip' -w "$f %{size_download} bytes %header{content-encoding}\n" http://localhost/$f; done index.nginx-debian.html 397 bytes gzip style.css 72074 bytes app.js 36731 bytes ------------------------------------------------------------------------------ The check's source (scripts/live/checks/nginx-gzip-brotli-ubuntu.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB: gzip and Brotli compression in Nginx on Ubuntu 26.04 and 24.04 (run per release, --releases=26.04,24.04): what Ubuntu already compresses (gzip is ON, but only for * HTML), the "gzip directive is duplicate" error from the usual copy-paste, the settings in their own file in * conf.d, check it with curl (sizes before and after, Vary), the Via header that turns compression off for a request * that came through a proxy (gzip_proxied), Brotli from Ubuntu's own module packages (no compiling), which encoding * wins when a client accepts both, and the undo, including what happens when the module is removed while its * config is still there. * * The server is a fresh VM box from Ubuntu's cloud image, reached as the sudo user `deploy`. Hidden setup, as the * earlier articles leave it: ufw on with SSH and 'Nginx Full', Nginx installed, and the default site holding a * stylesheet and a script of a realistic size (style.css, app.js), so there is something worth compressing. */ import { readFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { bareBox, reportBox } from '../lib.mjs' /** * Real files, so the sizes are honest (a generated, repetitive file shrinks ~97% and misleads): Lighthouse's report * stylesheet (Apache-2.0) and esquery's minified build (BSD-3-Clause), from this repository's node_modules. */ const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..') const ASSETS = { 'style.css': readFileSync(join(root, 'node_modules/lighthouse/report/assets/styles.css')), 'app.js': readFileSync(join(root, 'node_modules/esquery/dist/esquery.min.js')), } /** Copy a file to the box in pieces (one SSH argument may not exceed 128 KB). */ const upload = (L, name, buf) => { L(`sudo truncate -s 0 /var/www/html/${name}`) for (let i = 0; i < buf.length; i += 30000) L(`echo ${buf.subarray(i, i + 30000).toString('base64')} | base64 -d | sudo tee -a /var/www/html/${name} > /dev/null`) } export const meta = {} const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' const FILES = (enc) => `for f in index.nginx-debian.html style.css app.js; do curl -s -o /dev/null -H 'Accept-Encoding: ${enc}' -w "$f %{size_download} bytes %header{content-encoding}\\n" http://localhost/$f; done` const TYPES = 'text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml' const WRONG = `sudo tee /etc/nginx/conf.d/compression.conf > /dev/null <<'EOF' gzip on; gzip_types ${TYPES}; EOF` const GZIP = `sudo tee /etc/nginx/conf.d/compression.conf > /dev/null <<'EOF' # gzip is already on in /etc/nginx/nginx.conf: do not repeat "gzip on;" here gzip_vary on; gzip_comp_level 6; gzip_min_length 256; gzip_types ${TYPES}; EOF` const BROTLI = `sudo tee /etc/nginx/conf.d/brotli.conf > /dev/null <<'EOF' brotli on; brotli_comp_level 6; brotli_min_length 256; brotli_types ${TYPES}; EOF` /** " bytes " lines → { file: { bytes, enc } } */ const parse = (out) => Object.fromEntries( out .split('\n') .map((l) => l.trim().split(/\s+/)) .filter((p) => p.length >= 3) .map(([f, b, , e]) => [f, { bytes: Number(b), enc: e ?? '' }]), ) const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() L('sudo true') // ── hidden: as the UFW and Nginx articles leave the server, plus a site with a stylesheet and a script ────── L('sudo ufw allow OpenSSH && sudo ufw --force enable') L('sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx', 900000) L("sudo ufw allow 'Nginx Full'") for (const [name, buf] of Object.entries(ASSETS)) upload(L, name, buf) const sizes = L('stat -c %s /var/www/html/style.css /var/www/html/app.js') ctx.check( '(setup) Nginx serves the default site with a real stylesheet and a real minified script, byte for byte', L('systemctl is-active nginx') === 'active' && sizes === `${ASSETS['style.css'].length}\n${ASSETS['app.js'].length}`, sizes, ) // ── step 1: what is compressed now ────────────────────────────────────────────────────── const grep = run('grep -n gzip /etc/nginx/nginx.conf', { id: 'grep-gzip' }) ctx.check('nginx.conf already says "gzip on;", and the other gzip lines are commented out', /\d+:\s*gzip on;/.test(grep.out) && /#\s*gzip_types/.test(grep.out), grep.out) const before = run(FILES('gzip'), { id: 'files-before' }) const b = parse(before.out) ctx.check(`the HTML page comes back gzip, but style.css and app.js do NOT (gzip_types defaults to text/html)`, b['index.nginx-debian.html']?.enc === 'gzip' && !b['style.css']?.enc && !b['app.js']?.enc, before.out) // ── the usual copy-paste: gzip on; again ──────────────────────────────────────────────── run(WRONG, { id: 'write-wrong' }) const dup = run('sudo nginx -t', { id: 'test-duplicate' }) ctx.check('nginx -t fails: "gzip" directive is duplicate in /etc/nginx/conf.d/compression.conf:1', dup.exit !== 0 && /"gzip" directive is duplicate in \/etc\/nginx\/conf\.d\/compression\.conf:1/.test(dup.out), dup.out) // ── step 2: the settings in their own file ────────────────────────────────────────────── const w = run(GZIP, { id: 'write-gzip' }) ctx.check('compression.conf is written again (tee prints nothing with > /dev/null)', w.exit === 0 && w.out === '', w.out) const t1 = run('sudo nginx -t', { id: 'test-gzip' }) ctx.check('nginx -t is successful', t1.exit === 0 && /test is successful/.test(t1.out), t1.out) run('sudo systemctl reload nginx', { id: 'reload-gzip' }) // ── step 3: check it ──────────────────────────────────────────────────────────────────── const after = run(FILES('gzip'), { id: 'files-gzip' }) const a = parse(after.out) ctx.check('now all three come back gzip, and the CSS and JS are much smaller', ['index.nginx-debian.html', 'style.css', 'app.js'].every((f) => a[f]?.enc === 'gzip') && a['style.css'].bytes < b['style.css'].bytes / 2 && a['app.js'].bytes < b['app.js'].bytes / 2, after.out) const hdr = run("curl -sI -H 'Accept-Encoding: gzip' http://localhost/style.css | grep -iE '^(content-type|content-encoding|vary)'", { id: 'headers-gzip' }) ctx.check('the response says Content-Encoding: gzip and Vary: Accept-Encoding', /Content-Encoding: gzip/i.test(hdr.out) && /Vary: Accept-Encoding/i.test(hdr.out), hdr.out) const plain = run("curl -sI http://localhost/style.css | grep -iE '^(content-length|content-encoding)'", { id: 'headers-plain' }) ctx.check('a client that does not ask for gzip gets the plain file (Content-Length, no Content-Encoding)', /Content-Length: \d+/i.test(plain.out) && !/Content-Encoding/i.test(plain.out), plain.out) // ── behind a proxy: Via ───────────────────────────────────────────────────────────────── const via = run(`curl -s -o /dev/null -H 'Accept-Encoding: gzip' -H 'Via: 1.1 proxy' -w "%{size_download} bytes %header{content-encoding}\\n" http://localhost/style.css`, { id: 'via-off' }) ctx.check('with a Via header (the request came through a proxy) style.css is NOT compressed: gzip_proxied is off', !/gzip/.test(via.out), via.out) run("echo 'gzip_proxied any;' | sudo tee -a /etc/nginx/conf.d/compression.conf", { id: 'add-proxied' }) const t2 = run('sudo nginx -t && sudo systemctl reload nginx', { id: 'reload-proxied' }) ctx.check('nginx -t is successful with gzip_proxied any', t2.exit === 0, t2.out) const via2 = run(`curl -s -o /dev/null -H 'Accept-Encoding: gzip' -H 'Via: 1.1 proxy' -w "%{size_download} bytes %header{content-encoding}\\n" http://localhost/style.css`, { id: 'via-on' }) ctx.check('with gzip_proxied any, the proxied request is compressed too', /gzip/.test(via2.out), via2.out) // ── step 4: Brotli ────────────────────────────────────────────────────────────────────── const pol = run('apt-cache policy libnginx-mod-http-brotli-filter', { id: 'brotli-policy' }) ctx.check(`Ubuntu ${RELEASE} has the Brotli module as a package (universe)`, /Candidate: \S+/.test(pol.out) && !/Candidate: \(none\)/.test(pol.out), pol.out) const inst = run('sudo apt install -y libnginx-mod-http-brotli-filter', { id: 'brotli-install', timeout: 900000 }) ctx.check('apt installs the Brotli filter module', inst.exit === 0 && /Setting up libnginx-mod-http-brotli-filter/.test(inst.out), inst.out.slice(-1500)) const me = run('ls /etc/nginx/modules-enabled/', { id: 'modules-enabled' }) ctx.check('the package turned the modules on itself (modules-enabled holds a brotli file)', /brotli/.test(me.out), me.out) run(BROTLI, { id: 'write-brotli' }) const t3 = run('sudo nginx -t', { id: 'test-brotli' }) ctx.check('nginx -t is successful with brotli.conf', t3.exit === 0 && /test is successful/.test(t3.out), t3.out) run('sudo systemctl reload nginx', { id: 'reload-brotli' }) const br = run(FILES('br'), { id: 'files-br' }) const r = parse(br.out) ctx.check('asking for br: all three come back br, smaller than gzip', ['index.nginx-debian.html', 'style.css', 'app.js'].every((f) => r[f]?.enc === 'br') && r['style.css'].bytes < a['style.css'].bytes, br.out) const both = run(FILES('gzip, deflate, br'), { id: 'files-both' }) const w2 = parse(both.out) ctx.check('a client that accepts "gzip, deflate, br" (as browsers do over HTTPS) gets br', ['style.css', 'app.js'].every((f) => w2[f]?.enc === 'br'), both.out) const ce = L("curl -sI -H 'Accept-Encoding: br' http://localhost/style.css | grep -i '^content-encoding'") ctx.check('(a stylesheet asked for with br comes back br)', /content-encoding: br/i.test(ce), ce, { reader: { cmd: "curl -sI -H 'Accept-Encoding: br' http://localhost/ | grep -i '^content-encoding'", expect: '^Content-Encoding: br' }, }) const cg = L("curl -sI -H 'Accept-Encoding: gzip' http://localhost/style.css | grep -i '^content-encoding'") ctx.check('(and with gzip, gzip)', /content-encoding: gzip/i.test(cg), cg, { reader: { cmd: "curl -sI -H 'Accept-Encoding: gzip' http://localhost/ | grep -i '^content-encoding'", expect: '^Content-Encoding: gzip' }, }) ctx.stepsDone() // the article's steps end here; the undo (and the remove-the-module mistake) follows reportBox( ctx, L, `A fresh Ubuntu ${RELEASE} server from Ubuntu’s cloud image, with ufw on and Nginx installed as the earlier articles leave it, serving the default site plus a real 72 KB stylesheet and a real 37 KB minified script from open-source projects; reached over SSH as a sudo user.`, ['nginx', 'libnginx-mod-http-brotli-filter', 'curl'], ) // ── undo, and the mistake: removing the module while its config is still there ───────── const rm = run('sudo apt remove -y libnginx-mod-http-brotli-filter', { id: 'brotli-remove', timeout: 900000 }) ctx.check('apt removes the module, and its own reload of Nginx FAILS: "Job for nginx.service failed", action "reload" failed', /Job for nginx\.service failed/.test(rm.out) && /action "reload" failed/.test(rm.out), rm.out) const t4 = run('sudo nginx -t', { id: 'test-after-remove' }) ctx.check('nginx -t now fails: unknown directive "brotli" in /etc/nginx/conf.d/brotli.conf:1', t4.exit !== 0 && /unknown directive "brotli" in \/etc\/nginx\/conf\.d\/brotli\.conf:1/.test(t4.out), t4.out) const act = run('systemctl is-active nginx', { id: 'active-after-remove' }) ctx.check('the site is still up: nginx keeps running on the config it loaded before', act.out === 'active' && /200/.test(L("curl -s -o /dev/null -w '%{http_code}' http://localhost/")), act.out) const rs = run('sudo systemctl restart nginx', { id: 'restart-fails' }) ctx.check('but a restart (or a reboot) fails, and the site is DOWN: "Job for nginx.service failed"', rs.exit !== 0 && /Job for nginx\.service failed/.test(rs.out) && L('systemctl is-active nginx') !== 'active' && L("curl -s -o /dev/null -w '%{http_code}' http://localhost/") === '000', rs.out) run('sudo rm /etc/nginx/conf.d/brotli.conf /etc/nginx/conf.d/compression.conf', { id: 'undo-rm' }) const t5 = run('sudo nginx -t && sudo systemctl start nginx', { id: 'undo-start' }) ctx.check('with both files gone, nginx -t is successful and Nginx starts again', t5.exit === 0 && /test is successful/.test(t5.out) && L('systemctl is-active nginx') === 'active', t5.out) const back = run(FILES('gzip'), { id: 'files-undo' }) const u = parse(back.out) ctx.check('back to Ubuntu’s default: only the HTML page is gzip', u['index.nginx-debian.html']?.enc === 'gzip' && !u['style.css']?.enc, back.out) }) export default check