按 ESC 键关闭

CentOS/Red Hat 如何安装 Nginx 官方最新版

nginx
nginx

1、先安装先决条件:yum-utils

sudo yum install yum-utils -y

2、设置yum repos

创建文件/etc/yum.repos.d/nginx.repo

sudo vi /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

[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

默认情况下,安装稳定版(stable)nginx,如果要安装主线版本(mainline) nginx包,请运行以下命令:

sudo yum-config-manager --enable nginx-mainline

3、安装nginx

sudo yum install nginx -y

查看nginx版本

nginx -v

nginx version: nginx/1.16.0

3、启动 nginx

#启动
systemctl start nginx
#检查状态
systemctl status nginx
#设置自启动
systemctl enable nginx

到此,Nginx安装结束。

官方英文原文:http://nginx.org/en/linux_packages.html#RHEL-CentOS