Brotli is a free and open-source generic-purpose lossless compression algorithm that compresses data using various methods. It is similar in speed to deflate or gzip but offers more dense compression for Apache or Nginx web server. Nginx does not support Brotli, but we can install a module developed by Google called ngx_brotli to add support to Nginx. This page explains how to add or install Brotli support to Nginx on an OpenSUSE Linux server 15.2 to speed up webpages.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | OpenSUSE Linux 15.1/15.2 with Nginx |
Time | 5m |
OpenSUSE install Brotli module for Nginx
We can search for Nginx server using the zypper command as follows:
sudo zypper search nginx
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
---+----------------------------------------+---------------------------------------------------------------------------------+--------
| dehydrated-nginx | Nginx Integration for dehydrated | package
| fcgiwrap-nginx | System services for using fcgiwrap with nginx | package
i | nginx | A HTTP server and IMAP/POP3 proxy server | package
| nginx-geolite-asn | IP ASN geolocation databases for nginx | package
| nginx-geolite-city | Free IP city geolocation databases for nginx | package
| nginx-geolite-country | Free IP country geolocation databases for nginx | package
| nginx-ingress-controller | Kubernetes ingress controller for nginx | package
i+ | nginx-module-brotli | NGINX module for Brotli compression | package
| nginx-module-cookie-flag | The Nginx module for adding cookie flag | package
| nginx-module-devel-kit | Additional generic tools for nginx module development | package
| nginx-module-devel-kit-source | The nginx-module-devel-kit source | package
| nginx-module-http-auth-digest | Digest Authentication for Nginx | package
| nginx-module-http-substitutions-filter | Regular expression and fixed string substitutions nginx filter module | package
| nginx-module-modsecurity | ModSecurity v3 Nginx Connector | package
| nginx-module-set-misc | Various set_xxx directives added to nginx's rewrite module | package
| nginx-module-sticky-ng | Nginx module to add a sticky cookie to be forwarded to the same upstream server | package
| nginx-module-vts | Nginx virtual host traffic status module | package
| nginx-source | The nginx source | package
| pagure-web-nginx | Nginx configuration for Pagure | package
| pcp-pmda-nginx | Performance Co-Pilot (PCP) metrics for the Nginx Webserver | package
| python2-certbot-nginx | Nginx plugin for Certbot | package
| python3-certbot-nginx | Nginx plugin for Certbot | package
| rubygem-passenger-nginx | Passenger Nginx module | package
i+ | vim-plugin-nginx | VIM support for nginx config files | package
Let us install nginx and nginx-module-brotli.
Step 1 – Installing nginx on OpenSUSE
I am using openSUSE Leap version 15.2. I am going to install nginx/1.16.1 as follows:
sudo zypper install nginx vim-plugin-nginx
See “How to install and use Nginx on OpenSUSE Linux server” for more info.
Step 2 – Installing Brotli module for Nginx on OpenSUSE
Next, type the following command to install Brotil on OpenSUSE for freshly installed Nginx:
sudo zypper install nginx-module-brotli
Step 3 – OpenSUSE nginx config for Brotli
Edit the /etc/nginx/nginx.conf, run:
sudo vi /etc/nginx/nginx.conf
Add/edit as follows after worker_processes auto; line:
load_module lib64/nginx/modules/ngx_http_brotli_static_module.so; load_module lib64/nginx/modules/ngx_http_brotli_filter_module.so;
Here is how my config file looks:
user nginx; worker_processes auto; # load_module lib64/nginx/modules/ngx_http_fancyindex_module.so; # load_module lib64/nginx/modules/ngx_http_geoip_module.so; load_module lib64/nginx/modules/ngx_http_headers_more_filter_module.so; # load_module lib64/nginx/modules/ngx_stream_module.so; load_module lib64/nginx/modules/ngx_http_brotli_static_module.so; load_module lib64/nginx/modules/ngx_http_brotli_filter_module.so; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /run/nginx.pid; worker_rlimit_nofile 65535; events { worker_connections 65535; use epoll; multi_accept on; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $upstream_cache_status - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; charset utf-8; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; client_max_body_size 16M; server_tokens off; log_not_found off; include conf.d/*.conf; include vhosts.d/*.conf; }
Step 4 – Turn on brotli support for Nginx on OpenSUSE
Finally add the following in your server context. For instance I added the following to my /etc/nginx/vhosts.d/cyberciti.biz.conf file:
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types application/atom+xml application/javascript application/json application/rss+xml
application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
Step 5 – Restart or reload Nginx web server
Now that we installed and configured the Brotil module for Nginx. Check Nginx server config file for syntax errors:
nginx -t
We will see confirmation as follows:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
No errors means we can gracefully restart Nginx web server after changes made:
sudo systemctl reload nginx
Check status of the Nginx server:
sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2021-01-09 15:41:44 UTC; 6 days ago Process: 68339 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS) Process: 539 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Main PID: 543 (nginx) Tasks: 0 CGroup: /system.slice/nginx.service ├─ 543 nginx: master process /usr/sbin/nginx -g daemon off; ├─68340 nginx: worker process └─68341 nginx: worker process Jan 14 15:56:53 opensuse-nixcraft systemd[1]: nginx.service: Failed to reset devices.list: Operation not permitted Jan 16 09:14:17 opensuse-nixcraft systemd[1]: Reloading The nginx HTTP and reverse proxy server. Jan 16 09:14:17 opensuse-nixcraft systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Step 4 – Test it
Open the terminal and type the following curl command to see if your website support content encoding using Brotli. The syntax is:
curl -sILH 'Accept-Encoding: br' https://www.cyberciti.biz
Testing Brotli support Nginx on OpenSUSE server
Related: How to find if a website using gzip / deflate compression using curl on Linux and Unix
Another option is to open Firefox/Chrome developer tools and look for the network tab. You must see Content-Encoding: br headers. That also confirms Brotil is working correctly on OpenSUSE Linux for the Nginx web server. For example:
Summing up
And there you have it, and we added Brotli support for Nginx on the OpenSUSE Linux server. Please see ngx_brotli documentation on Github.
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |