Install brotli

  1. cd /usr/local/src
  2. Git clone github.com/google/ngx_…
  3. cd ngx_brotli
  4. git submodule update –init
  5. Then you can happily install Nginx

Install nginx

  1. First, install the latest version of Nginx (for example, I installed version 1.18.0)
  2. Download the decompression package and place it in /usr/local/src and CD it to that location
  3. Tar -zxvf nginx-1.18.0.tar.gz Decompressed
  4. CD nginx-1.18.0 Access the nginx directory
  5. ./configure –prefix=/www/server/nginx –with-http_gzip_static_module –with-http_stub_status_module –add-module=/ WWW /ngx_brotli –prefix =/ WWW /ngx_brotli
  6. make && make install

Two problems occur with older versions of Nginx, while newer versions do not

This is where the point comes in

I got two errors here. The first one is

Nginx /objs/Makefile, remove -werror from CFLAGS, and make again

The second is the

Just go to SRC/OS/Unix /ngx_user.c and comment out the line

Configure nginx

Input nginx -t prompt similar to the following the correct nginx: the configuration file/WWW/server/nginx/conf/nginx. Conf syntax is ok nginx: configuration file /www/server/nginx/conf/nginx.conf test is successfulCopy the code

Then go to the sbin folder in the nginx installation directory and type./nginx to start nginx

And then open the port

Firewall-cmd --add-port=80/ TCP --permanent # restart firewalldCopy the code

Configure GZIP and BR

Open the nginx.conf configuration file

Add the following to HTTP

Enable and disable gzip mode gzip on; Gzip_min_length 1k; # change the buffers of gzip_buffers 4 16k; # change the buffers of gzip_buffers 4 16k; Gzip_static on; #nginx will search for files that end with.gz and return them directly. Gzip_http_version 1.1; gzip_http_version 1.1; # gzip_comp_level 1; # gzip_comp_level 1; The type of file to compress. gzip_types text/plain application/json application/javascript application/x-javascript text/javascript text/css application/xml image/jpeg image/gif image/png video/mpeg audio/x-pn-realaudio audio/x-midi audio/basic audio/mpeg audio/ogg audio/* video/mp4; "Vary: accept-encoding "gzip_vary on; # Enabled for nginx as a reverse proxy,off(to turn off compression of all proxy results),expired(to enable compression if the header contains the "Expires" header),no-cache(to enable compression if the header contains "cache-control :no-cach") E "),no-store(compression enabled with header containing "cache-control :no-store"),private(compression enabled with header containing" cache-control :private"), no_last_mo______ (open Use compression,header does not contain "last-Modified "),no_etag(compression enabled, if header does not contain "Etag" header information),auth(compression enabled, if header header contains "Authorization" header information) gzip_proxied expired no-cache no-store private auth; # (IE5.5 and IE6 SP1 use the mSIE6 parameter to disable gzip compression) to specify which browsers do not need gzip compression (which will match user-agents), depending on the PCRE library gzip_disable "MSIE [1-6]\.";Copy the code
# Whether to enable on-the-fly compression of files. If enabled, files will be compressed and returned in response. brotli on; # When enabled, it checks for precompressed files with br extensions. If the value is always, the compressed file is always used, regardless of whether the browser supports it. brotli_static always; Set the compression quality level. The value ranges from 0 to 11. Brotli_comp_level 6. Set the number and size of buffers. The default size is the size of a memory page, which is 4K or 8K. brotli_buffers 16 8k; Set the minimum response size to compress. brotli_min_length 20; # specify which content encoding types are compressed. Text/HTML content is always compressed brotli_types Text /plain Application/JSON application/javascript application/ X-javascript text/javascript text/css application/xml image/jpeg image/gif image/png video/mpeg audio/x-pn-realaudio audio/x-midi audio/basic audio/mpeg audio/ogg audio/* video/mp4;Copy the code

Nginx -s reload nginx -s reload

conclusion

When BR is enabled, the first screen loads ten times faster, but BR only works in HTTPS mode. HTTP only works in GZIP