Debian 默认安装的 Nginx 对 WebDav 的支持有限,需要重新进行编译和安装第三方功能模块,以下是具体流程 ( 以安装 WebDav 模块为例 ):
1 安装必要的依赖
1 2
| sudo apt update sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev wget
|
2 下载 Nginx 源代码
从官方站点 https://nginx.org/download/ 挑选需要的 nginx 源代码,本文以 nginx 1.28.0 stable 为例。
1 2 3 4 5 6 7 8 9 10
| cd /usr/local/src wget http://nginx.org/download/nginx-x.x.x.tar.gz 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 功能拓展模块,将克隆的第三方模块文件夹放在 nginx 源码文件夹内准备编译。
1
| git clone https://github.com/arut/nginx-dav-ext-module
|
克隆完成后,开始编译,执行以下脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| ./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 \
|
4 安装新编译的 Nginx 服务
上步脚本编译和运行成功后,输入以下指令进行安装:
5 验证和启动 Nginx 服务
验证新的二进制文件及配置文件是否可以正确运行:
然后重新启动 nginx 服务:
1
| sudo systemctl restart ngnix
|
这样就完成了带有 WebDAV 支持的新版本 Ngnix 的构建与部署过程。
