centos7安裝nginx服務

2022-07-30 06:09:09 字數 2754 閱讀 5569

nginx發音引擎x是乙個免費的開源高效能http和反向**伺服器,負責處理網際網路上一些最大的**的負載。 本教程將教你如何在你的centos

linux 7.5機器上安裝和管理nginx。

安裝nginx

nginx包可在epel儲存庫中找到。

如果您沒有安裝epel儲存庫,可以執行以下命令:

sudo yum install epel-release

我們現在可以通過執行以下命令來安裝nginx包:

sudo yum install nginx

如果這是您第一次從epel儲存庫安裝包裝,yum可能會提示您匯入epel gpg金鑰:

從 file:///etc/pki/rpm-gpg/rpm-gpg-key-epel-7 檢索金鑰

匯入 gpg key 0x352c64e5:

使用者id    : "fedora

epel (7) "

指紋      : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5

軟體包    : epel-release-7-11.noarch (@extras)

來自      : /etc/pki/rpm-gpg/rpm-gpg-key-epel-7

是否繼續?[y/n]:y

如果是這種情況,請鍵入y並按enter鍵。

安裝完成後,啟用並啟動nginx服務:

sudo systemctl enable nginx

sudo systemctl start nginx

如果您正在執行防火牆,則還需要開啟埠80和443:

我們現在可以檢查nginx服務的狀態和版本:

sudo systemctl status nginx

示例輸出:

active: active (running) since 二 2018-05-15 10:09:59 cst; 57s ago

process: 7149 execstart=/usr/sbin/nginx (code=exited, status=0/success)

process: 7147 execstartpre=/usr/sbin/nginx -t (code=exited, status=0/success)

process: 7142 execstartpre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/success)

main pid: 7151 (nginx)

cgroup: /system.slice/nginx.service

├─7151 nginx: master process /usr/sbin/nginx

└─7152 nginx: worker process

5月 15 10:09:58 localhost.localdomain systemd[1]: starting the nginx http an...

5月 15 10:09:59 localhost.localdomain nginx[7147]: nginx: the configuration ...

5月 15 10:09:59 localhost.localdomain nginx[7147]: nginx: configuration file...

5月 15 10:09:59 localhost.localdomain systemd[1]: failed to read pid from fi...

5月 15 10:09:59 localhost.localdomain systemd[1]: started the nginx http and...

hint: some lines were ellipsized, use -l to show in full.

sudo nginx -v

nginx version: nginx/1.12.2

最後,我們可以通過在您選擇的瀏覽器中開啟http//your_ip來驗證安裝,並且您應該能夠看到預設的nginx歡迎頁面,如下所示:

使用systemctl管理nginx服務

我們可以像任何其他系統單元一樣管理nginx服務。

要停止nginx服務,請執行:

sudo systemctl stop nginx

要再次啟動,請鍵入:

sudo systemctl start nginx

重新啟動nginx服務:

sudo systemctl restart nginx

sudo systemctl reload nginx

如果你想禁用nginx服務在啟動時啟動:

sudo systemctl disable nginx

並重新啟用它:

sudo systemctl enable nginx

CentOS7安裝 Apache HTTP 伺服器

點選 11457次 不管你因為什麼原因使用伺服器,大部分情況下你都需要乙個 http 伺服器執行 多 使用者端指令碼和很多其它的東西。安裝 apache 伺服器 listen 80 把埠號 80 改為其它任何埠 例如 3221 儲存並退出。更改 apache 埠 允許 http 服務通過防火牆 永久...

centos7安裝nginx與nginx配置檔案

yum install gcc c nginx原始碼編譯需要 yum install y pcre pcre devel nginx 的 http 模組使用 pcre 來解析正規表示式yum install y zlib zlib devel nginx 使用zlib對http包的內容進行gzipy...

Centos7 編譯安裝Nginx

nginx版本分開發版和穩定版,生產環境使用穩定版,實驗新功能,新特性可以使用開發版。安裝nginx編譯需要依賴的包 yum install gcc gcc c wget yum install pcre devel zlib devel openssl devel說明 zlib nginx提供gz...