yum 安装
安装依赖
[root@localhost ~]# yum install yum-utils -y
添加 yum 源
创建 /etc/yum.repos.d/nginx.repo 文件,内容如下
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
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=0
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
安装
[root@localhost ~]# yum install nginx -y
开启端口
如果系统开启了防火墙,需要开启端口才能远程访问
[root@localhost rpm]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@localhost rpm]# firewall-cmd --reload
服务管理
启动
[root@localhost ~]# service nginx start
停止
[root@localhost ~]# service nginx stop
重启
[root@localhost ~]# service nginx restart
热启动
[root@localhost ~]# nginx -s reload
参考链接
nginx官方安装说明文档:https://nginx.org/en/linux_packages.html#RHEL-CentOS
nginx官方下载地址:https://nginx.org/en/download.html