跳转至

ntlm: NTLM NGINX 模块

安装

您可以在任何基于 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-ntlm
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-ntlm

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

load_module modules/ngx_http_upstream_ntlm_module.so;

本文档描述了 nginx-module-ntlm v1.19.4,于 2024 年 5 月 04 日发布。


NTLM 模块允许使用 NTLM 认证 代理请求。一旦客户端发送的请求中包含以 "Negotiate" 或 "NTLM" 开头的 "Authorization" 头字段值,上游连接将绑定到客户端连接。后续客户端请求将通过同一上游连接进行代理,从而保持认证上下文。

如何使用

语法: ntlm [connections]; 默认值: ntlm 100; 上下文: upstream

upstream http_backend {
    server 127.0.0.1:8080;

    ntlm;
}

server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        # 接下来的 2 个设置是确保 keepalive 正常工作的必要条件
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

connections 参数设置保存在缓存中的最大上游服务器连接数。

语法: ntlm_timeout timeout; 默认值: ntlm_timeout 60s; 上下文: upstream

设置在空闲连接到上游服务器时保持打开的超时时间。

测试

为了运行测试,您需要在系统上安装 nodejs 和 perl。

## 安装测试框架
cpan Test::Nginx

## 设置您的 nginx 位置路径
export PATH=/opt/local/nginx/sbin:$PATH

prove -r t

GitHub

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