Centos 下安装 Nginx(新)

今天重新实践了下 CentOS 7.6 下安装 Nginx,总结了一条更直接并简单的方式

从官方获取写入 nginx.repo 的方式

从官网查看文档,获取 nginx.repo 的文档内容,将其内容写入到指定的文件

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

将上面内容保存到文件 /etc/yum.repos.d/nginx.repo

运行 yum

运行 yum 安装命令,系统自动选择合适的仓库配置安装不出意外的话将会选择 nginx-stable 的配置

yum install nginx

将 nginx 设置为默认启动

成功安装后,运行 systemctl 命令,将 nginx 设置为系统运行时自动启动,如有需要运行其它 systemctl 命令

systemctl enable nginx

其它 systemctl 命令

systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

猜你喜欢

转载自www.cnblogs.com/cinlap/p/11795025.html