Nginx 编译及安装第三方模块
Table of contents:
Debian 默认安装的 Nginx 对 WebDav 的支持有限,需要重新进行编译和安装第三方功能模块,以下是具体流程 ( 以安装 WebDav 模块为例 ):
1 安装必要的依赖
sudo apt update
sudo apt install build-essential git libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev wget
2 下载 Nginx 源代码
从官方站点 https://nginx.org/download/ 挑选需要的 nginx 源代码,本文以 nginx 1.28.0 stable 为例。
cd /usr/local/src
wget http://nginx.org/download/nginx-x.x.x.tar.gz # 替换 x.x.x 为你所需的版本号
tar -zxvf nginx-x.x.x.tar.gz
cd nginx-x.x.x/
# 以下仅供参考
cd /usr/local/src
wget http://nginx.org/download/nginx-1.28.0.tar.gz
tar -zxvf nginx-1.28.0.tar.gz
cd nginx-1.28.0/
3 配置和编译必要模块
进入 nginx 的源码文件夹后,执行以下命令,安装 nginx-dav-ext-module 和 headers-more-nginx-module 功能拓展模块,将克隆的第三方模块文件夹放在 nginx 源码文件夹内准备编译。
git clone https://github.com/arut/nginx-dav-ext-module
git clone https://github.com/openresty/headers-more-nginx-module
克隆完成后,开始编译,执行以下脚本:
# 准备构建软件包,生成 Makefile,并指定安装路径、日志路径和所需模块。
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module \
--with-threads \
--with-stream \
--with-http_gzip_static_module \
--with-mail \
--with-http_dav_module \
--add-module=./nginx-dav-ext-module \
--add-module=./headers-more-nginx-module
--prefix:指定 Nginx 安装的基础目录;--sbin-path:指定主执行文件的位置;--conf-path:指定主配置文件的位置;--error-log-path/--http-log-path/--pid-path:指定错误日志、访问日志和 PID 文件的位置;--with-http_ssl_module:启用 HTTP SSL 模块,用于支持 HTTPS;--with-http_v2_module:启用 HTTP/2 协议支持模块;--with-http_v3_module:启用 HTTP/3 协议支持模块;--with-threads:允许使用多线程模式,以提高性能;--with-stream:支持 TCP 和 UDP 流量代理;--with-http_gzip_static_module:使 Nginx 能够直接发送预先压缩好的.gz文件,提高传输效率;--with-mail:启用 SMTP、IMAP 和 POP3 邮件代理模块;--with-http_dav_module:启用 WebDAV 功能,使得可以通过 Web 接口进行文件管理操作;--add-module=./nginx-dav-ext-module:添加扩展 WebDAV 模块,提供更多 DAV 操作功能;--add-module=./headers-more-nginx-module:添加 headers-more 模块,可以更灵活地设置或清除响应头信息。
4 安装新编译的 Nginx 服务
上步配置完成后,输入以下指令进行编译和安装:
make # 编译 Nginx
sudo make install # 安装新版本 Nginx 到指定路径中
5 验证和启动 Nginx 服务
验证新的二进制文件及配置文件是否可以正确运行:
nginx -t # 测试配置语法是否正确
然后重新启动 nginx 服务:
sudo systemctl restart nginx # 重启服务
这样就完成了带有 WebDAV 支持的新版本 Nginx 的构建与部署过程。
