Skip to content

CentOS 8 安裝 Nginx 1.18 版本

  • Linux

CentOS 8 預設從 AppStream安裝 Nginx 版本為 1.14 版,需要安裝 1.18 版本或指定版本可根據下方步驟進行修改。

先把環境更新到最新,安裝 Repository 套件庫。

[AAA@server ~]$ dnf update -y 
#更新至最新版本
[AAA@server ~]$ reboot 
#重新啟動
[AAA@server ~]$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
#安裝 Repository 套件庫
Last metadata expiration check: 0:00:20 ago on Sun 05 Jul 2020 04:48:26 PM UTC.
remi-release-8.rpm                                                             19 kB/s |  23 kB     00:01    
Dependencies resolved.
==============================================================================================================
 Package                   Architecture        Version                        Repository                 Size
==============================================================================================================
Installing:
 remi-release              noarch              8.1-2.el8.remi                 @commandline               23 k
Installing dependencies:
 epel-release              noarch              8-8.el8                        extras                     23 k

Transaction Summary
==============================================================================================================
Install  2 Packages

Total size: 46 k
Total download size: 23 k
Installed size: 49 k
Downloading Packages:
epel-release-8-8.el8.noarch.rpm                                               154 kB/s |  23 kB     00:00    
--------------------------------------------------------------------------------------------------------------
Total                                                                          62 kB/s |  23 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                      1/1 
  Installing       : epel-release-8-8.el8.noarch                                                          1/2 
  Installing       : remi-release-8.1-2.el8.remi.noarch                                                   2/2 
  Running scriptlet: remi-release-8.1-2.el8.remi.noarch                                                   2/2 
  Verifying        : epel-release-8-8.el8.noarch                                                          1/2 
  Verifying        : remi-release-8.1-2.el8.remi.noarch                                                   2/2 

Installed:
  epel-release-8-8.el8.noarch                        remi-release-8.1-2.el8.remi.noarch                       

Complete!
[AAA@server ~]$

環境準備好後列出可以使用的Nginx 版本及設定。

[AAA@server ~]$ sudo dnf module list nginx
#列出可以使用的 nginx 版本
Last metadata expiration check: 2:09:50 ago on Sun 05 Jul 2020 02:33:51 PM UTC.
CentOS-8 - AppStream
Name               Stream                Profiles                Summary                     
nginx              1.14 [d]              common [d]              nginx webserver             
nginx              1.16                  common [d]              nginx webserver             

Extra Packages for Enterprise Linux Modular 8 - x86_64
Name               Stream                Profiles                Summary                     
nginx              mainline              common                  nginx webserver             
nginx              1.18 [e]              common                  nginx webserver             

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[AAA@server ~]$ 

重設 Nginx 軟體版本

[root@mainpagev1-13 ~]$ sudo dnf module reset nginx
Last metadata expiration check: 0:01:33 ago on Sun 05 Jul 2020 04:52:55 PM UTC.
Dependencies resolved.
==============================================================================================================
 Package                   Architecture             Version                   Repository                 Size
==============================================================================================================
Resetting modules:
 nginx                                                                                                       

Transaction Summary
==============================================================================================================

Is this ok [y/N]: y
Complete!

[AAA@server ~]$ 

指定 Nginx 安裝 1.18 版本。

[AAA@server ~]$ sudo dnf module enable nginx:1.18 -y
Last metadata expiration check: 0:01:49 ago on Sun 05 Jul 2020 04:52:55 PM UTC.
Dependencies resolved.
==============================================================================================================
 Package                   Architecture             Version                   Repository                 Size
==============================================================================================================
Enabling module streams:
 nginx                                              1.18                                                     

Transaction Summary
==============================================================================================================

Complete!
[AAA@server ~]$ 

已經指定好所需版本後,再確認版本是否選定成1.18版本。

[AAA@server ~]$ sudo dnf module list nginx
Waiting for process with pid 1566 to finish.
Last metadata expiration check: 0:00:01 ago on Sun 05 Jul 2020 04:58:13 PM UTC.
CentOS-8 - AppStream
Name                    Stream                    Profiles                    Summary                         
nginx                   1.14 [d]                  common [d]                  nginx webserver                 
nginx                   1.16                      common [d]                  nginx webserver                 

Extra Packages for Enterprise Linux Modular 8 - x86_64
Name                    Stream                    Profiles                    Summary                         
nginx                   mainline                  common                      nginx webserver                 
nginx                   1.18 [e]                  common                      nginx webserver                 

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[AAA@server ~]#

透過 dnf 安裝 Nginx 軟體。

[AAA@server ~]$ sudo dnf install nginx -y
Last metadata expiration check: 0:00:09 ago on Sun 05 Jul 2020 04:58:13 PM UTC.
Dependencies resolved.
==============================================================================================================
 Package                   Architecture  Version                                    Repository           Size
==============================================================================================================
Installing:
 nginx                     x86_64        1:1.18.0-1.module_el8+8815+5a98f081        epel-modular        580 k
Installing dependencies:
 centos-logos-httpd        noarch        80.5-2.el8                                 BaseOS               24 k
 gperftools-libs           x86_64        2.7-6.el8                                  epel                315 k
 libunwind                 x86_64        1.3.1-3.el8                                epel                 75 k 
nginx-filesystem          noarch        1:1.18.0-1.module_el8+8815+5a98f081        epel-modular         24 k

Transaction Summary
==============================================================================================================
Install  5 Packages

Total download size: 1.0 M
Installed size: 3.6 M
Downloading Packages:
(1/5): centos-logos-httpd-80.5-2.el8.noarch.rpm                               371 kB/s |  24 kB     00:00    
(2/5): nginx-filesystem-1.18.0-1.module_el8+8815+5a98f081.noarch.rpm          250 kB/s |  24 kB     00:00    
(3/5): nginx-1.18.0-1.module_el8+8815+5a98f081.x86_64.rpm                     2.8 MB/s | 580 kB     00:00    
(4/5): libunwind-1.3.1-3.el8.x86_64.rpm                                       136 kB/s |  75 kB     00:00    
(5/5): gperftools-libs-2.7-6.el8.x86_64.rpm                                   346 kB/s | 315 kB     00:00    
--------------------------------------------------------------------------------------------------------------
Total                                                                         562 kB/s | 1.0 MB     00:01     
warning: /var/cache/dnf/epel-modular-95d9a0c53e492cbd/packages/nginx-1.18.0-1.module_el8+8815+5a98f081.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Extra Packages for Enterprise Linux Modular 8 - x86_64                         76 kB/s | 1.6 kB     00:00    
Importing GPG key 0x2F86D6A1:
 Userid     : "Fedora EPEL (8) <epel@fedoraproject.org>"
 Fingerprint: 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                      1/1 
  Installing       : libunwind-1.3.1-3.el8.x86_64                                                         1/5 
  Installing       : gperftools-libs-2.7-6.el8.x86_64                                                     2/5 
  Running scriptlet: nginx-filesystem-1:1.18.0-1.module_el8+8815+5a98f081.noarch                          3/5 
  Installing       : nginx-filesystem-1:1.18.0-1.module_el8+8815+5a98f081.noarch                          3/5 
  Installing       : centos-logos-httpd-80.5-2.el8.noarch                                                 4/5 
  Installing       : nginx-1:1.18.0-1.module_el8+8815+5a98f081.x86_64                                     5/5 
  Running scriptlet: nginx-1:1.18.0-1.module_el8+8815+5a98f081.x86_64                                     5/5 
  Verifying        : centos-logos-httpd-80.5-2.el8.noarch                                                 1/5 
  Verifying        : nginx-1:1.18.0-1.module_el8+8815+5a98f081.x86_64                                     2/5 
  Verifying        : nginx-filesystem-1:1.18.0-1.module_el8+8815+5a98f081.noarch                          3/5 
  Verifying        : gperftools-libs-2.7-6.el8.x86_64                                                     4/5 
  Verifying        : libunwind-1.3.1-3.el8.x86_64                                                         5/5 

Installed:
  centos-logos-httpd-80.5-2.el8.noarch                                                                        
  gperftools-libs-2.7-6.el8.x86_64                                                                            
  libunwind-1.3.1-3.el8.x86_64                                                                                
  nginx-1:1.18.0-1.module_el8+8815+5a98f081.x86_64                                                            
  nginx-filesystem-1:1.18.0-1.module_el8+8815+5a98f081.noarch                                                 

Complete!
[AAA@server ~]$

重新檢查 Nginx 版本是否正確

[AAA@server ~]$ nginx -v
#檢查 nginx 版本卻確認為 1.18.0
nginx version: nginx/1.18.0
[AAA@server ~]$

Nginx 常用指令

最後附上常用 nginx 相關指令。

sudo systemctl start nginx
#啟動Nginx服務

sudo systemctl restart nginx
#重新啟動Nginx服務

sudo systemctl enable nginx
#設定開機時啟動Nginx

sudo systemctl status nginx
#確認 Nginx 服務的狀態

以下指令請先自行備份 /etc/nginx 目錄下的所有檔案
以下指令請先自行備份 /etc/nginx 目錄下的所有檔案
以下指令請先自行備份 /etc/nginx 目錄下的所有檔案


sudo dnf remove nginx -y
#移除 Nginx
rm -rf /etc/nginx/
#刪除 /etc/nginx/ 資料夾

參考來源

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。