admin avatar

nginx 开启http3 QUIC和配置Brotli压缩和反向代理的详细教程

🕣 by admin

nginx 开启http3 QUIC和配置Brotli压缩和反向代理的详细教程

nginx 配置http3 QUIC参阅这篇文章

https://www.vpslala.com/t/403

在上面的配置中编译Nginx时添加以下代码

1
2
git clone https://github.com/google/ngx_brotli
 cd ngx_brotli && git submodule update --init

下面时演示代码,具体路径自行修改

1
2
3
4
5
6
7
8
9
10
11
12
./configure --prefix=/usr/local/nginx --user=www-data --group=www-data --pid-path=/var/run/ginx.pid \
   	--with-http_ssl_module              	\
   	--with-http_v2_module               	\
   	--with-http_v3_module               	\
             --with-http_stub_status_module     \
              --with-http_gzip_static_module   \
              --with-http_realip_module          \
             --add-module=/opt/ngx_brotli    \
   	--with-openssl=../quiche/deps/boringssl \
   	--with-quiche=../quiche \
             --with-pcre=/opt/pcre-8.44 \
            --with-zlib=/opt/zlib-1.2.11 
开启Brotli压缩,添加以下代码到nginx.confserver

1
2
3
4
# brotli
             brotli on;
             brotli_comp_level 5;
             brotli_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml

如果安装遇到问题,请自行参考以下文章

https://www.vpslala.com/t/403

下面时配置nginx反向代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 location / {
              proxy_pass    http://127.0.0.1:9090;
              proxy_set_header Host $host;
              proxy_redirect off;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_connect_timeout 300;
              proxy_read_timeout 300;
              proxy_send_timeout 300;
              }

             location ^~ /avatar/ {
             root /home/wwwroot/demo/static;
             }
//请求头像地址直接在网站根目录static目录下查找
             location ~* \.(js|css)$ {
            root        /home/wwwroot/demo/static/;
            }
//同上
            
           location ~* \.(gif|ico|bmp|png|jpg|jpeg)$ {
           root        /home/wwwroot/demo/upload;
           }
//图片的存放目录

💘 相关文章

写一条评论