Featured image of post Nginx安装与卸载

Nginx安装与卸载

nginx 安装与卸载

安装 nginx

通过nginx搭建 webdav服务 需要安装http_dav_module模块。nginx-full版本中直接包含了http_dav_module模块。

1 、安装 nginx-full(webdav服务版)

1
sudo apt update && sudo apt install nginx-full -y

2 、查看 nginx 版本

1
nginx -v

3 、启动 nginx 服务

1
systemctl start nginx

4 、查看 nginx 状态

1
sudo systemctl status nginx

5 、设置 nginx 开机自动启动

1
sudo systemctl enable nginx

6 、升级 nginx-full

1
sudo apt update && sudo apt upgrade nginx-full -y

nginx 维护命令

1 、测试配置文件

1
sudo nginx -t

2 、重启nginx服务

1
sudo systemctl restart nginx

3 、判断配置文件格式是否正确

1
nginx -t

4 、查看当前 Nginx 最终的配置

1
nginx -T

5 、重新加载配置文件

1
nginx -s reload

6 、检查 nginx 服务是否已启用(输出 enabled 表示服务已成功启用)

1
sudo systemctl is-enabled nginx

7 、优雅停止Nginx

1
nginx -s quit

8 、强制停止Nginx

1
sudo systemctl stop nginx

9 、重新加载 .bashrc 文件

1
source ~/.bashrc 

10 、查看nginx日志

1
2
3
cat /var/log/nginx/error.log
# sudo tail -f /var/log/nginx/error.log
# sudo journalctl -u nginx

11 、测试特定的nginx配置文件是否正确

1
nginx -t -c /etc/nginx/conf.d/xunlei.conf

12 、查看 80 端口占用情况

1
netstat -tulnp | grep "0.0.0.0:80"

卸载 nginx

1 、卸载 nginx-full

1
sudo apt remove nginx-full -y

2 、卸载 nginx 及其配置文件

1
sudo apt remove --purge nginx-full -y

3 、卸载 nginx 删除所有自动生成的配置文件和日志文件

1
sudo apt autoremove --purge nginx-full -y
最后更新于 2025-02-22
本博客已稳定运行 小时 分钟
共发表 112 篇文章 · 总计 109.83 k 字
本站总访问量