Nginx启用Brotli压缩算法
cd /usr/local/data/soft/
git clone https://github.com/google/ngx_brotli
cd ngx_brotli && git submodule update --init
#重新编译nginx
#进到nginx源码目录下
cd nginx-1.14.2
#预编译
./configure --prefix=/usr/local/data/nginx-1.14.2 \
--user=www --group=www --with-http_ssl_module \
--with-http_stub_status_module --with-http_gzip_static_module \
--with-pcre --with-http_v2_module --with-http_secure_link_module \
--with-stream --with-openssl-opt=enable-tlsext --with-http_flv_module \
--add-module=/usr/local/data/soft/ngx_brotli
#编译
make #我这里没有make install
cp /usr/local/data/nginx-1.14.2/sbin/nginx /usr/local/data/nginx-1.14.2/sbin/nginx-old
#kill掉nginx
ps axu|grep nginx|awk '{print $2}'|xargs kill -9
#替换nginx
cp objs/nginx /usr/local/data/nginx-1.14.2/sbin/nginx
#启动nginx
/usr/local/data/nginx-1.14.2/sbin/nginx
nginx.conf配置文件中新增
brotli on;
brotli_static on;
brotli_comp_level 6;
brotli_buffers 16 128k;
brotli_min_length 20;
brotli_types text/css application/x-javascript application/xml application/x-httpd-php text/javascript application/javascript text/xml application/json image/jpeg image/png image/jpg;
重新加载配置文件
/usr/local/data/nginx-1.14.2/sbin/nginx -t
nginx: the configuration file /usr/local/data/nginx-1.14.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/data/nginx-1.14.2/conf/nginx.conf test is successful
#reload加载
/usr/local/data/nginx-1.14.2/sbin/nginx -s reload
访问时网上打不开
查阅资料
反向代理添加这个配置
proxy_set_header Accept-Encoding "";
location / {
proxy_set_header Accept-Encoding "";
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
重新reload
网站访问正常
打开浏览器查看br已经生效
标签:1.14,--,data,brotli,nginx,反向,usr,local From: https://blog.51cto.com/ziyu/6687821