温馨提示×

nginx在debian如何卸载

小樊
43
2026-09-18 15:41:45
栏目: 智能运维

在 Debian 系统下卸载 nginx,通常可以按以下步骤操作(根据你当初的安装方式略有不同)。


一、如果是用 apt 安装的(最常见)

1. 停止 nginx 服务

sudo systemctl stop nginx
sudo systemctl disable nginx

2. 卸载 nginx 软件包

sudo apt remove nginx nginx-common nginx-full nginx-light nginx-core

如果你想彻底删除配置文件

sudo apt purge nginx nginx-common nginx-full nginx-light nginx-core

3. 清理无用依赖

sudo apt autoremove

二、删除残留文件和目录(可选但推荐)

即使卸载了,以下目录可能还存在:

sudo rm -rf /etc/nginx
sudo rm -rf /var/log/nginx
sudo rm -rf /var/www/html  # 如果你放了网站文件
sudo rm -rf /usr/share/nginx

三、如果你是用源码编译安装的

如果是 make && make install 安装的:

  1. 找到安装路径(通常是 /usr/local/nginx
which nginx
  1. 删除目录
sudo rm -rf /usr/local/nginx
  1. 删除 systemd 服务(如果有)
sudo rm -f /etc/systemd/system/nginx.service
sudo systemctl daemon-reload

四、确认是否卸载干净

nginx -v

如果提示 command not found,说明已卸载成功。


如果你能告诉我:

  • Debian 版本(如 11 / 12)
  • 当初是怎么装的(apt / 源码 / docker)

我可以给你更精确的命令。

0