1. 程式人生 > >CentOS下yum安裝NGINX

CentOS下yum安裝NGINX

使用yum安裝nginx出錯 yum -y install nginx

已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
沒有可用軟體包 nginx。
錯誤:無須任何處理

沒有nginx軟體包!!! 很多軟體包在yum裡面沒有的,解決的方法,就是使用epel源,也就是安裝epel-release軟體包。EPEL(Extra Packages for Enterprise Linux)是基於Fedora

的一個專案,為“紅帽系”的作業系統提供額外的軟體包,適用於RHEL、CentOS等系統。可以在下面的網址上找到對應的系統版本,架構的軟體包。

http://dl.fedoraproject.org/pub/epel/

安裝epel

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm

rpm -ivh epel-release-7-9.noarch.rpm

也可以直接使用yum 安裝 yum install epel-release

或者使用

 rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝成功之後,再安裝nginx yum install nginx

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

[[email protected] yum.repos.d]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
[[email protected] 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相關的驗證命令及啟動命令

[[email protected] yum.repos.d]# nginx                    
[[email protected] 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
[[email protected] yum.repos.d]# nginx -s reload             

nginx啟動

nginx -t測試命令

nginx -s relaod修改nginx.conf之後,可以過載