官方链接:http://nginx.org/en/linux_packages.html#RHEL-CentOS
环境:centos7
1、安装依赖
sudo yum install yum-utils
2、到/etc/yum.repos.d/目录下创建一个以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
3、默认情况下,使用稳定 nginx 包的存储库。如果您想使用主线 nginx 包,请运行以下命令:
sudo yum-config-manager --enable nginx-mainline
4、安装nginx
sudo yum install nginx
5、启动nginx
systemctl start nginx
6、测试访问
curl IP地址
7、查看nginx安装路径
[root@localhost ~]# rpm -qa|grep nginx
nginx-1.21.4-1.el7.ngx.x86_64
[root@localhost ~]# rpm -ql nginx-1.21.4-1.el7.ngx.x86_64
8、卸载nginx
yum remove nginx