快轉到主要內容
  1. Posts/

重新安裝Nginx會遇到的問題

Linux Linux Nginx
目錄

作業系統 : Ubuntu

前言
#

起初以為安裝、解除安裝任何套件就是

$ sudo apt-get install module

$ sudo apt-get remove module

直到遇到Nginx時,才發現這招已經行不通了

1. 安裝
#

首先,先安裝一次Nginx,使用Ubuntu下的模組管理工具

$ sudo apt-get install nginx

2. 解除安裝
#

同樣使用apt來移除Nginx

$ sudo apt-get remove nginx

這邊使用autoremove來移除不需要的依賴套件

$ sudo apt-get autoremove

刪除nginx資料夾

$ sudo rm -rf /etc/nginx

3. 重新安裝Nginx
#

$ sudo apt-get update

$sudo apt-get install nginx

接著就會看到console報錯了

dpkg: error processing package nginx (--configure):
 dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Errors were encountered while processing:
 nginx-core
 nginx

上網爬了文後,找到解法如下

$ sudo apt-get --purge remove nginx

這樣可以移除不再需要的依賴套件

再使用一次autoremove

$ sudo apt-get autoremove

接著查看還有沒有與Nginx相關的套件

$ dpkg --get-selections | grep nginx

如果還有看到nginx相關的套件,不要懷疑

$ sudo apt-get --purge remove 套件名稱

重新安裝 Nginx
#

$ sudo apt-get install nginx

檢查版本

nginx -v

並執行nginx的設定語法檢查

sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Ernie
作者
Ernie

相關文章

使用 Supervisor 管理 Linux 服務
Linux Python Supervisor Flask Gunicorn Linux Python
學習如何在Linux環境下使用Supervisor管理Flask+Gunicorn應用程式。
在 Ubuntu 上設定高效能 uWSGI 伺服器
Python Web Server Ubuntu UWSGI WSGI Python Ubuntu Web Server Nginx Deployment
本文介紹如何在 Ubuntu 上設定 uWSGI 伺服器,並與 Python 應用程式整合,提升效能與穩定性。
有效清理Ubuntu系統的安裝套件
Ubuntu Linux Ubuntu 套件管理 系統清理 磁碟空間
學習如何使用apt-get clean, apt-get autoclean, apt-get remove, 和 apt-get autoremove 命令清理和移除Ubuntu系統中不需要的套件,釋放磁碟空間。