跳转至

doh: NGINX 模块用于处理 DNS-over-HTTPS (DOH) 请求

安装

您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:

  • RedHat Enterprise Linux 7, 8, 9 和 10
  • CentOS 7, 8, 9
  • AlmaLinux 8, 9
  • Rocky Linux 8, 9
  • Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-doh
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-doh

通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用该模块:

load_module modules/ngx_http_doh_module.so;

本文档描述了 nginx-module-doh v0.1,于 2020 年 1 月 15 日发布。


简单的 Nginx 模块,用于处理 DNS-over-HTTPS (DOH) 请求。

警告:该模块是实验性的,尽管我已经成功地在 Firefox 和 Curl 中使用它,但可能存在未发现的错误。目前不正式支持区域传输。

已在以下 Nginx 版本中测试: 1.16.1 (稳定版) 1.17.6 1.17.7 (主线)。

有关构建、安装和使用 Nginx 模块的说明,请参阅以下链接。

动态模块: https://www.nginx.com/resources/wiki/extending/converting/#compiling-dynamic

静态模块: https://www.nginx.com/resources/wiki/extending/compiling/

我提供了一个配置文件,用于同时构建动态和静态模块。

该模块仅允许在 http location 块中使用。

模块指令

doh: (不接受参数)在此 location 块中启用 DOH,默认上游 DNS 服务器地址为 127.0.0.1,默认端口为 53,默认超时时间为 5 秒。

doh_address: (接受 1 个参数)设置上游 DNS 服务器的地址,可以是 IPv4 或 IPv6。

doh_port: (接受 1 个参数)设置与上游 DNS 服务器联系的端口(适用于 TCP 和 UDP 连接)。

doh_timeout: (接受 1 个参数)设置超时时间(以秒为单位)。

示例

最简单的用例,上游 DNS 服务器在 127.0.0.1 的 53 端口上监听:

location /dns-query {
    doh;
}

设置上游地址为 127.0.2.1,端口为 5353,超时时间为 2 秒:

location /dns-query {
    doh;
    doh_address 127.0.2.1;
    doh_port 5353;
    doh_timeout 2;
}

GitHub

您可以在 nginx-module-doh 的 GitHub 仓库 中找到有关此模块的其他配置提示和文档。