-
-
Enable Brotli Compression on Nginx, CWP and on Linux OS for official nginx
Not Working on CWP 9.5 AlmaLinux as of today due to version mismatch of module and nginx server I am currently on nginx-1.28.0 Here’s a complete step-by-step I followed to get Brotli compression working in my CWP (AlmaLinux 9.5) Nginx stack. Hope it will help some body This Tutorial is future version ready!!! 1. Install Build Dependenciessudo dnf install -y epel-release sudo dnf groupinstall "Development Tools" -y sudo dnf install -y \ gcc make pcre2-devel zlib-devel openssl-devel git \ brotli brotli-develbrotli/brotli-devel gives you the CLI compressor (optional but useful). The rest are needed to compile the Nginx module. 2. Clone the ngx_brotli Modulecd /usr/local/src sudo git clone https://github.com/google/ngx_brotli.git cd ngx_brotli sudo git submodule update --init 3. Download Matching Nginx Source# Find your installed Nginx version NGINX_VER=$(nginx -v 2>&1 | awk -F/ '{print $2}') cd /usr/local/src sudo curl -LO http://nginx.org/download/nginx-$NGINX_VER.tar.gz sudo tar zxvf nginx-$NGINX_VER.tar.gz 4. Compile Only the Dynamic Brotli Modulecd nginx-$NGINX_VER sudo ./configure \ --with-compat \ --add-dynamic-module=../ngx_brotli sudo make modulesThis produces two files in objs/: ngx_http_brotli_filter_module.so ngx_http_brotli_static_module.so 5. Install the Compiled Modulessudo mkdir -p /etc/nginx/modules sudo cp objs/ngx_http_brotli_filter_module.so \ objs/ngx_http_brotli_static_module.so \ /etc/nginx/modules/ 6. Enable the Modules in NginxEdit your main /etc/nginx/nginx.conf at the very top, before any events/http/stream blocks: load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;Be sure these lines come before the first worker_processes or events block. 7. Configure Brotli in Your HTTP ContextInside the http { ... } section of /etc/nginx/nginx.conf, add or adjust: # Compression brotli brotli on; brotli_comp_level 6; brotli_static on; brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml application/xhtml+xml text/javascript application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap;You can tune brotli_comp_level (1–11) and the MIME types as needed. 8. Test and Reloadsudo nginx -t sudo systemctl reload nginx9. VerifyCLI: brotli --version HTTP: Use curl to check the Content-Encoding header: curl -H "Accept-Encoding: br" -I https://your.domain/ You should see: Content-Encoding: brThat’s it - your CWP Nginx now serves Brotli-compressed responses
AmarBunty
Members
-
Joined
-
Last visited