1. 程式人生 > 實用技巧 >Linux CentOS8 安裝 Nginx

Linux CentOS8 安裝 Nginx

使用 yum 直接安裝:

yum install nginx

執行完成會出現 Complete! 表示安裝成功。

Linux sudo 命令以系統管理者的身份執行指令,也就是說,經由 sudo 所執行的指令就好像是 root 親自執行。
我都是使用root賬號直接操作的,非root賬號的朋友可以帶上 sudo。

啟用並啟動Nginx服務:

sudo systemctl enable nginx
sudo systemctl start nginx

停止服務:

sudo systemctl stop nginx

要驗證服務是否正在執行,檢查其狀態:

sudo systemctl status nginx

安裝完後訪問我們的站點即可看到紅白色的

Welcome to nginx on Red Hat Enterprise Linux!

不得不說比Windows的看起來有排面多了。

然後需要改配置。。給我愁的,搞了半天沒找到裝在哪裡了。

檢視nginx安裝目錄

Linux 中的 ps 命令是 Process Status 的縮寫。ps命令用來列出系統中當前執行的那些程序。
| 符號,是個管道符號,表示ps 和 grep 命令同時執行;
grep 命令是查詢(Global Regular Expression Print),能使用正則表示式搜尋文字,然後把匹配的行顯示出來;

輸入命令

ps  -ef | grep nginx

返回結果包含了安裝目錄 :

root      344802       1  0 09:08 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx     344803  344802  0 09:08 ?        00:00:00 nginx: worker process
root      392857  392766  0 15:04 pts/1    00:00:00 grep --color=auto nginx

但是我發現這裡沒有配置檔案 - -

檢視nginx.conf配置檔案目錄

輸入命令

nginx -t

返回結果包含配置檔案目錄
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

這樣就找到了配置檔案所在的位置,更改即可。
改完之後不要忘記重啟一下

ngins -s reload