卸载并清理安装的nginx
apt autoremove nginx
apt purge nginx
apt clean
编译安装Nginx
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar zxvf nginx-1.24.0.tar.gz
wget https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v3.0.0.tar.gz
tar zxvf v3.0.0.tar.gz
#v3.0.0.tar.gz解压后不用移动位置,在编译参数中已经指定了其路径
cd nginx-1.24.0
apt update
apt-get install libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev libxslt-dev libgd-dev libgeoip-dev apache2-utils gcc make
./configure --prefix=/etc/nginx --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module --with-stream --with-stream=dynamic --with-http_realip_module --with-http_v2_module --with-http_image_filter_module --with-http_image_filter_module=dynamic --with-http_ssl_module --add-module=/root/nginx-dav-ext-module-3.0.0
make && make install
cd /etc/nginx #必须在这个目录运行ln命令
ln -s /etc/nginx/sbin/nginx /usr/bin/nginx
nginx
执行nginx -V
查看有没有--add-module=/root/nginx-dav-ext-module-3.0.0
nginx加入到systemctl服务运行
nginx -s stop #停止nginx服务
nano /usr/lib/systemd/system/nginx.service
#nano /etc/systemd/system/nginx.service
输入以下内容并保存
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid #必须与nginx.conf中pid的设置相同
ExecStart=/etc/nginx/sbin/nginx
ExecReload=/etc/nginx/sbin/nginx -s reload
ExecStop=/etc/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
开机启动
重新载入
systemctl daemon-reload
设置开机启动
systemctl enable nginx
如果提示
Failed to enable unit: Unit file /etc/systemd/system/nginx.service is masked.
执行如下指令
systemctl unmask nginx
建立目录
mkdir /html
chmod -R 777 /html
nginx.conf配置
user root; #注意用户名
worker_processes 1;
error_log /etc/nginx/logs/error.log warn; #注意路径
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/conf/mime.types; #注意路径
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log /etc/nginx/logs/access.log main; #注意路径
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
client_max_body_size 20m;
#gzip on;
include /etc/nginx/conf/conf.d/*.conf;
}