1、进入在源目录下,下载nginx官方的repo源

[root@localhost centos]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Retrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
warning: /var/tmp/rpm-tmp.Sl1gsZ: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing...                          ################################# [100%]
        package nginx-release-centos-7-0.el7.ngx.noarch is already installed
[root@localhost yum.repos.d]# ll
total 44
-rw-r--r--. 1 root root 2523 Dec 13 16:18  CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23  2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Oct 23  2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Oct 23  2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Oct 23  2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23  2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23  2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Oct 23  2020 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root  113 Jul 15  2014 nginx.repo
[root@localhost yum.repos.d]#

此时目录下会多一个文件: CentOS-Base.repo

2、安装Nginx

yum install nginx -y

[root@localhost yum.repos.d]# nginx -v
nginx version: nginx/1.24.0

默认是最新版本的

3、启动,设置开机自启动

[root@localhost yum.repos.d]# nginx
[root@localhost yum.repos.d]# systemctl enable nginx
[root@localhost yum.repos.d]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-12-13 20:22:45 CST; 1h 32min ago
     Docs: http://nginx.org/en/docs/
 Main PID: 989 (nginx)
   CGroup: /system.slice/nginx.service
           ├─989 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─993 nginx: worker process

Dec 13 20:22:45 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
Dec 13 20:22:45 localhost.localdomain systemd[1]: Started nginx - high performance web server.