第一種方法:通過配置EPEL源,然后通過yum安裝Nginx服務
1、配置EPEL源,我這邊以阿里云鏡像為例(http://mirrors.aliyun.com/)
[root@static ~]# cd /etc/yum.repos.d/
[root@static yum.repos.d]# ll
total 24
-rw-r--r--. 1 root root 1991 Dec 1 16:16 CentOS-Base.repo
-rw-r--r--. 1 root root 647 Dec 1 16:16 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 289 Dec 1 16:16 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Dec 1 16:16 CentOS-Media.repo
-rw-r--r--. 1 root root 6259 Dec 1 16:16 CentOS-Vault.repo
[root@static yum.repos.d]# wget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.repo
--2017-12-01 16:17:36-- http://mirrors.aliyun.com/repo/epel-6.repo
Resolving mirrors.aliyun.com...
180.163.159.87, 180.163.159.88, 180.163.159.100, ...
Connecting to mirrors.aliyun.com|180.163.159.87|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1083 (1.1K) [application/octet-stream]
Saving to: “/etc/yum.repos.d/epel-6.repo”
100%[=====================================================================================================================================================>] 1,083 --.-K/s in 0s
2017-12-01 16:17:47 (150 MB/s) - “/etc/yum.repos.d/epel-6.repo” saved [1083/1083]
(如果wget命令沒有,請通過yum安裝(yum -y install wget)
[root@static yum.repos.d]#
[root@static yum.repos.d]# ll epel-6.repo (查看剛剛下載的epel,目錄里是否有)
-rw-r--r--. 1 root root 1083 Jul 2 2014 epel-6.repo
2、查看nginx的版本
[root@static ~]# yum info nginx

3、通過Yum安裝nginx
[root@static ~]# yum -y install nginx
4、通過yum安裝nginx的目錄結構
配置文件: /etc/nginx
啟動腳本:/etc/rc.d/init.d/nginx
腳本配置文件:/etc/sysconfig/nginx
nginx命令:/usr/sbin/nginx
模塊文件:/usr/lib64/nginx/modules
說明文檔目錄:/usr/share/doc/
日志切割:etc/logrotate.d/nginx
日志文件:/var/log/nginx
默認主目錄:/usr/share/nginx/html/
5、啟動Nginx服務并測試
[root@static ~]# service nginx start
Starting nginx: [ OK ]
[root@static ~]# ss -tunlp|grep 80
tcp LISTEN 0 128 :::80 :::* users:(("nginx",1587,7),("nginx",1589,7))
tcp LISTEN 0 128 *:80 *:* users:(("nginx",1587,6),("nginx",1589,6))
關閉防火墻,或者放行80端口的訪問
[root@static ~]# service iptables stop
[root@static ~]# iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
[root@static ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
關閉Selinux服務
[root@static ~]#setenforce 0 臨時關閉
[root@static ~]# sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
[root@static ~]# cat /etc/selinux/config (重啟服務器后生效)
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
測試訪問如下

第二種: 通過nginx yum repository安裝最新版本的nginx
1、配置yum源
[root@static ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
注意:
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.
2、查看nginx版本
[root@static ~]# yum info nginx

3、安裝nginx
[root@static ~]# yum -y install nginx
4、Nginx的目錄結構
配置文件: /etc/nginx
日志文件: /var/log/nginx
默認主目錄: /usr/share/nginx/html
模塊目錄: /usr/lib64/nginx/modules
啟動腳本:/etc/rc.d/init.d/nginx
說明文檔目錄: /usr/share/doc/
5、啟動nginx服務
[root@static nginx]# service nginx start
Starting nginx: [ OK ]
[root@static nginx]# ss -tunlp|grep nginx
tcp LISTEN 0 128 *:80 *:* users:(("nginx",1476,6),("nginx",1478,6))
- 第一部分:Nginx Web服務
- 第一章: Nginx的初探
- 第二章:Nginx的安裝部署
- 第一節:在centos6上通過Yum安裝Nginx
- 第二節:在Centos7上通過Yum安裝nginx
- 第三節:編譯安裝Nginx服務
- 第四節: Nginx編譯參數詳解
- 第五節: Nginx的啟動腳本
- 第六節:Nginx的shell腳本安裝
- 第七節:nginx服務的平滑升級
- 第三章:Nginx服務基礎配置
- 第一節: 配置運行nginx服務器用戶
- 第二節:配置運行生成的worker processes進程數
- 第三節:配置Nginx進程PID存放路徑
- 第四節:定義MIME類型
- 第五節:自定義nginx的訪問日志
- 第六節:主配置段(main)常用的配置
- 第七節:http段(核心)常用的配置命令
- 第八節:配置nginx中的location段
- 第九節: 基于IP的訪問控制
- 第十節:基于用戶的訪問控制
- 第十一節:Nginx定義status狀態頁
- 第十二節:Nginx服務器Rewrite重寫
- 第十三節:Nginx服務配置防盜鏈
- 第十四節:nginx軟件的優點
- 第四章:Nginx服務器的優化配置
- 第一節:nginx.conf配置文件基本參數優化
- 第二節:fastcgi調優
- 第三節:Gzip調優
- 第四節:expires緩存調優
- 第五節:內核參數優化
- 第六節: Nginx之——413 修改上傳文件大小限制
- 第五章:Nginx虛擬主機的配置
- 第一節:基于名稱的虛擬主機
- 第二節:通過shell腳本添加虛擬主機
- 第六章:Nginx常用模塊指令詳解
- 第一節:ngx_http_realip_module
- 第二節:http_image_filter_module
- 第三節:tengine中配置consistent hash module
- 第四節:ngx_http_userid_module
- 第七章:Nginx服務器配置HTTPS訪問
- 第八章: Nginx服務器日志切割
- 第二部分:Nginx負載均衡反向代理服務
- 第一章:Nginx進階參數詳解
- 第一節:proxy_module參數詳解
- 第二節:upstream_module參數詳解
- 第四章:Nginx反向代理服務
- 第一節:Nginx反向代理配置參數詳解
- 第二節:Nginx反向代理服務配置案例
- 第三節:Nginx緩存
- 第四節: Nginx中fastcgi模塊
- 第五節:nginx+fastcgi實現動靜分離架構
- 第五章:Nginx負載均衡
- 第一節:ngx_http_upstream_module常見指令
- 第二節:調度方法
- 第三節:健康狀態檢查