CentOS7 上安裝 Nginx

Nginx 是異步框架的網頁服務器,也可以用作反向代理、負載平衡器和 HTTP 緩存。該軟件由伊戈爾 · 賽索耶夫創建並於 2004 年首次公開發布。2011 年成立同名公司以提供支持。2019 年 3 月 11 日,Nginx 公司被 F5 Networks 以 6.7 億美元收購。Nginx 是免費的開源軟件,根據類 BSD 許可證的條款發佈.

前提條件

請確保你以具有 root 權限的用戶身份登錄, 並且你沒有在端口 80 或 443 上運行 Apache 或任何其他服務。

在 CentOS 上安裝 Nginx

按照以下步驟在 CentOS 服務器上安裝 Nginx:

1.Nginx 包在 EPEL 存儲庫中可用。如果你還沒有安裝 EPEL 存儲庫

> yum install epel-release

2. 通過 yum 命令安裝 Nginx:

> yum install nginx

如果這是你第一次從 EPEL 存儲庫安裝軟件包,yum 可能會提示你導入 EPEL GPG 密鑰:

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package    : epel-release-7-noarch (@extras)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]:

如果是這種情況,請鍵入y並點擊Enter

3. 安裝完成後,啓用並啓動 Nginx 服務:

> systemctl enable nginx //開機啓動
> systemctl start nginx  //啓動Nginx服務

使用以下命令檢查 Nginx 服務的狀態:

> systemctl status nginx

輸出應如下所示:

4. 防火牆開放端口

使用以下命令打開必要的端口:

> firewall-cmd --permanent --zone=public --add-service=http
> firewall-cmd --permanent --zone=public --add-service=https
> firewall-cmd --reload

5. 驗證 Nginx,瀏覽器輸入http://IP

使用 systemctl 管理 Nginx 服務

你可以像管理 任何其他 systemd 單元一樣管理 Nginx 服務。

Nginx 配置文件的結構和最佳實踐

/etc/nginx/nginx.conf
/etc/nginx/conf.d/rumenz.com.conf
/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
/usr/share/nginx/html
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/FD1wyiwHQvuarkhRvr2XCQ