本篇简单介绍如何在RHEL/CentOS安装最新版本的Nginx。
Step 1:安装yum-utils
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# yum install yum-utils -y
Step 2:
创建一个名为/etc/yum.repos.d/nginx.repo的配置文件,内容如下:
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=
enabled=
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=
enabled=
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
Step 3:(根据所需,可跳过)
默认情况下,使用稳定nginx包的存储库。如果要使用主线nginx包,请运行以下命令:
# sudo yum-config-manager --enable nginx-mainline
Step 4:安装nignx
# sudo yum install nginx -y
Step 5:查看版本
[root@localhost ~]# nginx -v # 稳定包版本
nginx version: nginx/1.16. [root@localhost ~]# nginx -v # 主线nginx
nginx version: nginx/1.17.
参考: