一、检查NGINX的编译参数
nginx -V
记录结果
nginx version: nginx/1.17.7
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.1.1d 10 Sep 2019
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua-nginx-module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc
用记事本等文本工具记录下来配置文件
二、下载nginx源码,下载对应的参数。
(如果你愿意,可以在面板中执行nginx的版本切换命令,执行过程中手动中断,找到bt官方的全部源码,理论上可以省去了下载各种插件的过程。)
1、下载nginx
(也可以用bt自己的nginx源码,路径是/www/server/nginx/src.tar.gz)
tar -zxvf /www/server/nginx/src.tar.gz /www/server/nginx/src
cd /www/server/nginx/src
2、按照上面的配置文件下载module插件
git clone https://github.com/vision5/ngx_devel_kit.git
git clone https://github.com/openresty/lua-nginx-module.git
git clone https://github.com/FRiCKLE/ngx_cache_purge.git
git clone https://github.com/lusis/nginx-sticky-module.git
git clone https://github.com/arut/nginx-dav-ext-module.git
注意1:
编译需要openssl插件,配置文件没提示,需要下载,然后指定--with-openssl=/www/server/nginx/src/openssl编译条件
wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
tar -zxvf openssl-1.1.1d.tar.gz
mv openssl-1.1.1d/ openssl
rm -f openssl-1.1.1d.tar.gz
注意2:
编译中需要pcre-8.43,否则make不通过,然后指定--with-pcre=pcre-8.43
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.bz2
tar -jxvf pcre-8.43.tar.bz2
注意3:
lua-nginx-module 插件建议使用低版本,否则启动nginx的时候有bug
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.zip
unzip v0.10.14.zip lua-nginx-module
[root@gao]# tailf /var/log/nginx/error.log
# 问题 1 沿用官方的 luajit v2.0.5 编译新版本 lua-nginx-module 应该会提示建议切换至 openresty 的 luajit v2.1 分支
2019/11/04 11:59:56 [alert] 2749#2749: detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
# 问题 2,解决方案是使用低版本 lua-nginx-module v0.10.14 ,使用最新版发现会触发该问题,等待官方修复
2019/11/04 11:59:56 [alert] 2749#2749: failed to load the 'resty.core' module ( https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
no field package.preload['resty.core']
no file './resty/core.lua'
no file '/usr/local/share/luajit-2.0.5/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core/init.lua'
no file './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so') in /etc/nginx/nginx.conf:117
注意4:
安装stick模块出现 MD5_DIGEST_LENGTH 报错
解决方式就是修改在你下载解压缩之后的sticky模块文件夹中的ngx_http_sticky_misc.c文件将这两个模块 openssl/sha.h 与 openssl/md5.h包含进去
#include <nginx.h> #include <ngx_config.h> #include <ngx_core.h> #include <ngx_http.h> #include <ngx_md5.h> #include <ngx_sha1.h> #include <openssl/sha.h> #include <openssl/md5.h> #include "ngx_http_sticky_misc.h"
综合以上,我们得出最后的编译参数
./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua-nginx-module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --add-module=nginx-dav-ext-module --with-http_dav_module
三、编译过程也不容易
1、执行配置参数报错,缺少luajit支持。那么
git clone https://github.com/openresty/luajit2.git
cd luajit2
make
make install
cd src
cp luajit /usr/local/bin/
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
注意5:
luajit的下载地址,必须是openresty的分支,不能是org官方分支,否则报错
nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
2、继续编译,基本就能通过了
3、make,其中注意4与注意2就是我经历的报错
4、拷贝旧的nginx做备份。将新的nginx挪进去
mv /www/server/nginx/sbin/nginx /www/server/nginx/sbin/nginx.old
cp objs/nginx /www/server/nginx/sbin/nginx
四、配置webdav
1、bt面板中建立站点。
2、修改配置文件,增加
location / {
charset utf-8;
autoindex on;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK PROPPATCH;
create_full_put_path on;
dav_access user:rw group:r all:r;
auth_basic "Authorized Users Only";
auth_basic_user_file /www/wwwroot/bt/.htpasswd;
}
注意6:
dav_ext_methods 中的 PROPPATCH 这个 response ,需要打补丁并重新编译.
补丁地址
https://github.com/arut/nginx-dav-ext-module/files/3835180/proppatch.patch.gz
描述地址: https://github.com/arut/nginx-dav-ext-module/issues/52
据说开启以后可以支持windows的自带webdav客户端写入。---我测试失败了。
3、填坑,用户文件.htpasswd怎么生成?经查,必须安装apache才能得到htpasswd命令,所以源码编译,make后拷贝出来而不安装行么?动手
wget https://www-eu.apache.org/dist/httpd/httpd-2.4.41.tar.gz
tar -zxvf httpd-2.4.41.tar.gz
cd httpd-2.4.41
./configure
.....
悲剧,缺少apr
wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
tar -zxvf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure
make && make install
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
./configure --with-apr=/usr/local/apr
make && make install
继续执行HTTPD的编译
./configure
make
cp ./support/htpasswd /usr/local/bin/
于是得到了htpasswd!!!
htpasswd -c /www/wwwroot/bt/.htpasswd www
后面的www为你要建立的用户名,紧接着输入密码,完事