Open felix-cao opened 6 years ago
之前有一篇文章是源码安装 centos 7 下 Nginx 的下载安装 #75, 本篇主要介绍 CentOS 7 环境下的yum 安装, CentOS 7 中的 yum 没法直接使用 yum install nginx 这个指令去安装 Nginx,因为 Nginx 这个服务不是 yum 库中自带的。
CentOS 7
yum
yum install nginx
Nginx
这里是 官方提供的 nginx 安装教程, 或者看看这个 Linux 系统下 Nginx 稳定的安装包
http://nginx.org/packages/centos/7/x86_64/RPMS/
$ 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。
$releasever
7
$basearch
x86_64
$releaseve
$ rpm -qa | grep centos-release
结果显示:
centos-release-7-4.1708.el7.centos.x86_64
$ yum list nginx $ yum install nginx
$ systemctl start nginx
$ systemctl status nginx
$ nginx -v nginx version: nginx/1.14.0
$ rpm -ql nginx
$ nginx -t
$ nginx -s reload
测试一下在本地是否可以访问。
$ curl -i localhost
启动:systemctl start nginx.service
停止:systemctl stop nginx.service
重启:systemctl restart nginx.service
设置开机自启动:systemctl enable nginx.service
停止开机自启动:systemctl disable nginx.service
查看当前状态:systemctl status nginx.service
查看所有已启动的服务:systemctl list-units --type=service
之前有一篇文章是源码安装 centos 7 下 Nginx 的下载安装 #75, 本篇主要介绍
CentOS 7
环境下的yum
安装,CentOS 7
中的yum
没法直接使用yum install nginx
这个指令去安装Nginx
,因为Nginx
这个服务不是yum
库中自带的。一、配置 yum 源
这里是 官方提供的 nginx 安装教程, 或者看看这个 Linux 系统下 Nginx 稳定的安装包
http://nginx.org/packages/centos/7/x86_64/RPMS/
输入如下内容
将
$releasever
替换为7
,将$basearch
替换成x86_64
。 通过下面这条指令获取你自己系统的$releaseve
r 和$basearch
。结果显示:
二、安装、启动及检测
2.1、安装 Nginx
2.2、启动 Nginx
2.3、检测是否启动
2.4、查看 nginx 版本
2.5、查看安装目录
2.6、检查配置文件是否正确
2.7、平滑重启 nginx
2.8、本地测试
测试一下在本地是否可以访问。
2.9、其他
启动:systemctl start nginx.service
停止:systemctl stop nginx.service
重启:systemctl restart nginx.service
设置开机自启动:systemctl enable nginx.service
停止开机自启动:systemctl disable nginx.service
查看当前状态:systemctl status nginx.service
查看所有已启动的服务:systemctl list-units --type=service