CentOS 7 yum安装nginx

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

在这里插入图片描述

在这里插入图片描述

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、可以使用两种方法启动nginx服务

[root@lnboxue ~]# service nginx start

[root@lnboxue ~]# systemctl start nginx

4、查看nginx服务是否已经启动

[root@lnboxue ~]# netstat -ntl

在这里插入图片描述

5、查看nginx版本

[root@lnboxue ~]# nginx -v
nginx version: nginx/1.12.0

6、本地测试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
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/diyiday/article/details/82787580