Skip to content

nginx http3 配置

https://www.cnblogs.com/zengxiangzhan/p/17299057.html

测试你的浏览器是否支持 http3 https://quic.nginx.org/

docker nginx http3

使用 GitHub 上提供的 docker-nginx-http3 镜像启动一个支持 HTTP/3 的示例,可以按照以下步骤进行:

1. 确保安装了 Docker:

首先,你需要确保你的系统上安装了 Docker。你可以在终端运行docker --version来检查 Docker 是否已经安装。

2. 下载 Docker 镜像:

你可以通过 Docker 命令从 Docker Hub 下载 macbre/nginx-http3 镜像。在你的终端运行以下命令:

bash
docker pull macbre/nginx-http3

3. 创建 nginx 配置文件:

创建一个简单的 nginx 配置文件(例如nginx.conf),以启用 HTTP/3。以下是一个基本的配置示例:

nginx
events {
}
http {
    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        listen 443 quic reuseport;

        ssl_certificate     /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;

        # Enable HTTP/3.
        add_header Alt-Svc 'h3-29=":443"'; # Adjust the protocol version as necessary
        ssl_protocols TLSv1.2 TLSv1.3;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
}

4. 准备 SSL 证书:

5. 运行 Docker 容器:

使用你创建的 nginx 配置文件和 SSL 证书运行 Docker 容器。将相应的文件夹挂载到容器内部相应的位置。例如:

bash
docker run -d --name my-nginx-http3 -p 443:443 -v ./nginx-ssl:/etc/nginx/ssl -v ./nginx.conf:/etc/nginx/nginx.conf  macbre/nginx-http3

6. 测试 HTTP/3 连接:

使用浏览器测试

测试你的浏览器是否支持 http3 https://quic.nginx.org/

  1. 需要打开 chrome 的 quic 配置,chrome 地址栏中输入下面的地址

chrome://flags/#enable-quic

  1. Experimental QUIC protocol 修改为 Enabled

  2. 重新加载浏览器

alt text

使用最新版本的 curl

GitHub issues https://github.com/macbre/docker-nginx-http3/issues/100#issuecomment-1611115316

  1. 下载安装 curl

最新 curl Windows 官网:https://curl.se/windows/

直接点击下载 Windows https://curl.se/windows/dl-8.7.1_7/curl-8.7.1_7-win64-mingw.zip

  1. 使用命令获取请求头信息
powershell
.\curl.exe --http3 -I https://docs.ffffee.com:8443
powershell
PS C:\Users\Administrator\Downloads\curl-8.7.1_7-win64-mingw\curl-8.7.1_7-win64-mingw\bin> .\curl.exe --http3 -I https://docs.ffffee.com:8443
HTTP/3 200
server: nginx/1.25.4
date: Tue, 23 Apr 2024 04:34:49 GMT
content-type: text/html
content-length: 846
last-modified: Mon, 22 Apr 2024 04:00:43 GMT
etag: "6625e0eb-34e"
cache-control: no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0
accept-ranges: bytes