nginx配置brotli压缩,并解决反向代理异常问题
  eCzDQ3mUTle2 2023年11月02日 109 0

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;

nginx配置brotli压缩,并解决反向代理异常问题_运维

重新加载配置文件

/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

访问时网上打不开

nginx配置brotli压缩,并解决反向代理异常问题_IT_02

查阅资料

反向代理添加这个配置

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已经生效

nginx配置brotli压缩,并解决反向代理异常问题_运维_03

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  jnZtF7Co41Wg   2023年12月11日   27   0   0 nginx客户端服务端
  nIt0XG0acU8j   2023年12月11日   31   0   0 linuxhtop
  jnZtF7Co41Wg   2023年12月10日   20   0   0 nginx客户端服务端NFS
eCzDQ3mUTle2