启用http3

启用http3

官方文档

https://nginx.org/en/docs/http/ngx_http_v3_module.html

有效实践

本站已经支持 http3

# 摘要出值得关注的几行 - 关键配置
server {
    listen 443 quic reuseport;
    listen [::]:443 quic reuseport;
    http3 on;

    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;

    server_name chenwx.top www.chenwx.top blog.chenwx.top m.chenwx.top;
    ssl_protocols TLSv1.3;
    add_header Alt-Svc 'h3=":443"; ma=600';
    location / {
        root /web/blog;
        index index.html;
    }
}

最核心也就4行

    listen 443 quic reuseport;
    listen [::]:443 quic reuseport;
    http3 on;
    add_header Alt-Svc 'h3=":443"; ma=600';

简述

  1. 需要开启防火墙的 udp 443 端口
  2. 浏览器默认首次访问一个站点还是使用的 http1 协议, 所以需要 add_header Alt-Svc 头部告知浏览器支持的协议

遗留问题

这个站点目前有2个主要域名 www.chenwx.top 和 docs.chenwx.top, 分别配置在 2 个 server{} 里面的;

早期配置的 "listen 443 ssl" 是可以在多个文件里面同时配置;

但是 "listen 443 quic reuseport" 就不支持多个 server{} 块里面进行监听, 就会报错监听冲突;

我来回测试了好几种AI给的配置办法都不可用。暂时放弃,只在主占启用了 h3, docs 这个后面再研究一下。

待后续测试。

最后更新于