centos7通過yum安裝nginx

金武飛揚發表於2019-01-19
yum install -y nginx

通過yum安裝的時候提示下面的錯誤

[root@localhost yum.repos.d]# yum install nginx
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
沒有可用軟體包 nginx。
錯誤:無須任何處理

需要新增nginx的源

[root@localhost yum.repos.d]# rpm -ivh http://nginx.org/packages/cen...

該命令執行之後,會在/etc/yum.respos.d下面多出一個nginx.repo

[root@localhost yum.repos.d]# ll
總用量 40
-rw-r--r--. 1 root root 1572 12月 1 2016 CentOS-Base.repo
-rw-r--r--. 1 root root 1572 12月 1 2016 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 1664 10月 24 10:36 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 8月 30 2017 CentOS-CR.repo
-rw-r--r--. 1 root root 649 8月 30 2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 8月 30 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 8月 30 2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月 30 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 8月 30 2017 CentOS-Vault.repo
-rw-r--r--. 1 root root 113 7月 15 2014 nginx.repo

然後再執行安裝命令

yum install -y nginx

安裝之後,可以檢視nginx的預設安裝目錄

[root@localhost yum.repos.d]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d

以下是Nginx的預設路徑:

(1) Nginx配置路徑:/etc/nginx/
(2) PID目錄:/var/run/nginx.pid
(3) 錯誤日誌:/var/log/nginx/error.log
(4) 訪問日誌:/var/log/nginx/access.log
(5) 預設站點目錄:/usr/share/nginx/html

事實上,只需知道Nginx配置路徑,其他路徑均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查詢到

nginx相關的驗證命令及啟動命令

root@localhost yum.repos.d]# nginx 
[root@localhost yum.repos.d]# nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost yum.repos.d]# nginx -s reload

nginx 啟動
nginx -t 測試命令
nginx -s relaod 修改nginx.conf之後,可以過載

相關文章