小編今天要來分享的是在Ubuntu Linux 安裝最新版本Nginx。
Nginx最新版本號查詢:
https://nginx.org/
1、新增套件更新來源
vim /etc/apt/sources.list.d/nginx.list
18.04(bionic)版本內容:
deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ bionic nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ bionic nginx
20.04(focal)版本內容:
deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ focal nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ focal nginx
2、匯入Nginx金鑰
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
3、更新apt
sudo apt update
4、移除舊有Nginx版本(如果之前有安裝Nginx)
sudo apt remove nginx nginx-common nginx-full nginx-core
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
5、安裝Nginx
sudo apt install nginx
6.設定開機啟動Nginx
systemctl enable nginx
7.其他常用指令
(1)、檢查版本
nginx -v
(2)、檢查運作狀態
systemctl status nginx
(3)、啟動nginx服務
systemctl start nginx
(4)、停止nginx服務運作
systemctl stop nginx
(5)、重新啟動nginx服務
systemctl restart nginx