编译 Nginx 作者: Hogwarts 发布于: 2023-07-31 更新于: 2023-11-05 分类: 默认分类 Nginx默认安装所带的dav模块不能满足实际的需求,需编译安装模块。以debian11为例。 #一、安装编译环境 apt install apt install gcc make libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev -y 以上依赖来源于网络,多搜搜就有了。不过可尝试自行安装openssl。 wget https://www.openssl.org/source/`openssl-1.1.1u.tar.gz` tar -zxvf openssl-1.1.1u.tar.gz #二、编译Nginx ##2.1 下载源码 wget https://nginx.org/download/nginx-1.24.0.tar.gz tar -zxvf nginx-1.24.0.tar.gz ##2.2 下载webdav模块 参考:`https://github.com/arut/nginx-dav-ext-module` wget https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v3.0.0.tar.gz tar -zxvf v3.0.0.tar.gz ##2.3 编译nginx flv_module也需提前下载 flv_module地址:`https://github.com/winshining/nginx-http-flv-module` wget https://github.com/winshining/nginx-http-flv-module/archive/refs/tags/v1.2.11.tar.gz tar -zxvf v1.2.11.tar.gz Nginx 编译 cd nginx-1.24.0 ./configure --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --with-openssl=../openssl-1.1.1u \ --modules-path=/usr/lib/nginx/modules \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --with-compat \ --with-file-aio \ --with-threads \ --with-http_addition_module \ --with-http_dav_module --add-module=/root/nginx-dav-ext-module-3.0.0 \ --with-http_flv_module --add-module=/root/nginx-http-flv-module-1.2.11 \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_sub_module \ --with-mail --with-mail_ssl_module \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-pcre \ --with-stream \ --with-http_mp4_module \ --with-http_auth_request_module \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_v2_module make make install ##2.4 检测编译情况 nginx -t #三、webdav的设置 ##3.1 设置访问用户名和密码 htpasswd -bc webdavpasswd yourname yourpassword htpasswd的用法参考:`https://ipcmen.com/htpasswd` 在Debian11下有可能报错:`-bash: htpasswd: command not found` apt install apache2-utils 本例使用的是htpasswd命令,也可用openssl命令生成。 本例参考的网站用的是`openssl passwd -crypt `命令,但在实践中有时报错。经Google得知:**openssl 3.0及之后的版本移除了 -crypt 选项**。 root@debian:openssl passwd -crypt myPassword -bash: openssl passwd -crypt myPassword: command not found root@debian:openssl version OpenSSL 3.0.11 19 Sep 2023 (Library: OpenSSL 3.0.11 19 Sep 2023) ##3.2 格式 location / { auth_basic "Please enter your username and password"; auth_basic_user_file /etc/nginx/conf.d/webdavpasswd; root /webdavpath; charset utf-8; autoindex on; autoindex_localtime on; autoindex_exact_size off; client_max_body_size 0; create_full_put_path on; dav_access user:rw group:rw all:r; dav_methods PUT DELETE MKCOL COPY MOVE; dav_ext_methods PROPFIND OPTIONS; } #四、开机启动 vim /etc/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/usr/sbin/nginx -s reload ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl start nginx systemctl status nginx systemctl enable nginx 可能用到的命令 pkill -9 nginx nginx -c /etc/nginx/nginx.conf nginx -s reload #五、参考 [编译Nginx及相关配置详解](https://hostalk.net/posts/nginx_make.html "编译Nginx及相关配置详解") [利用Nginx WebDAV搭建自己的网盘](https://www.cnblogs.com/DragonStart/p/13410090.html "利用Nginx WebDAV搭建自己的网盘") 标签: nginx, webdav