0%

[Nginx] CentOS 安裝網頁伺服器 Nginx

前言

相較於 Apache,Nginx 消耗資源少且處理速度快,又支援高併發,是大流量應用的好選擇。

環境

  • CentOS 8.2

安裝

開啟 Terminal,使用 dnf 來安裝 Nginx

1
2
3
4
5
[user@localhost ~]$ sudo dnf install -y nginx
...
...
...
Complete! #看到這就行代表完成

啟動並確認

Nginx 預設是沒有開啟的,預設當系統開機時也不會自動開啟,所以通過指令

1
2
[user@localhost ~]$ sudo systemctl start nginx   # 現在馬上開啟 nginx 服務
[user@localhost ~]$ sudo systemctl enable nginx # 之後開機也要自動開啟 nginx 服務

確認 Nginx 的服務狀態,看到 active (running) 代表正在運行囉

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[user@localhost ~]$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-09-10 09:08:10 CST; 3min 51s ago
Process: 2892 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 2890 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 2888 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 2893 (nginx)
Tasks: 3 (limit: 49448)
Memory: 5.7M
CGroup: /system.slice/nginx.service
├─2893 nginx: master process /usr/sbin/nginx
├─2894 nginx: worker process
└─2895 nginx: worker process

Sep 10 09:08:10 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Sep 10 09:08:10 localhost.localdomain nginx[2890]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 10 09:08:10 localhost.localdomain nginx[2890]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Sep 10 09:08:10 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
很高興能在這裡幫助到您,歡迎登入 Liker 為我鼓掌 5 次,或者成為我的讚賞公民,鼓勵我繼續創造優質文章。
以最優質的內容回應您的鼓勵