CentOS 7 yum安装nginx-1.12.0

CentOS 7 中的 yum 没法直接使用 yum install nginx 这个指令去安装nginx,因为nginx这个服务不是yum库中自带的。图1是官方提供的大致安装步骤,图2是官网提供的多个版本的nginx安装包,下面是我给合自己的系统环境总结的安装方法,供大家参考:

图1

图2

/etc/yum.repos.d/文件夹下执行

sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
  1. 按图1中的要求vi nginx.repo这个文件,将图中[nginx]字段中的内容复制进去,保存退出!

    [root@lnboxue ~]# vi  /etc/yum.repos.d/nginx.repo
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/7/x86_64/
    gpgcheck=0
    enabled=1

    这里需要注意的是:要将$releasever替换为7,将$basearch替换成x86_64。可以通过下面这条指令获取你自己系统的$releasever和$basearch。

    [root@lnboxue ~]# rpm -qa | grep centos-release
    centos-release-7-3.1611.el7.centos.x86_64
  2. yum安装nginx,参见图3和图4。

[root@lnboxue ~]# yum install nginx

图3

图4

  1. 可以使用两种方法启动nginx服务

[root@lnboxue ~]# service nginx start

[root@lnboxue ~]# systemctl start nginx

  1. 查看nginx服务是否已经启动

[root@lnboxue ~]# netstat -ntl

图5

  1. 查看nginx版本
[root@lnboxue ~]# nginx -v
nginx version: nginx/1.12.0
  1. 本地测试nginx服务

    [root@lnboxue ~]# curl -i localhost
    HTTP/1.1 200 OK
    Server: nginx/1.12.0
    Date: Tue, 04 Jul 2017 05:27:07 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Wed, 12 Apr 2017 15:23:46 GMT
    …………
    …………
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    <p>For online documentation and support please refer to
    nginx.org.<br/>
    Commercial support is available at
    nginx.com.</p>
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>

    看到以上信息,说明你的nginx服务已安装成功!