华为云ECS弹性服务器 Centos8 指定版本安装nginx

   

记录一下华为云ECS弹性服务器 Centos8 指定版本安装nginx,以备后查。

 

1、更新一下yum并设置阿里云仓库

  下载新的yum源,执行下面两条命令:

  > curl https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo > /etc/yum.repos.d/Centos-vault-8.5.2111.repo

  > curl https://mirrors.aliyun.com/repo/epel-archive-8.repo > /etc/yum.repos.d/epel-archive-8.repo

  

  然后执行yum -y update 进行更新:

  > yum -y update

 

  此时可以执行命令 dnf info nginx 来查看当前系统的nginx版本信息

  > dnf info nginx

  如果执行dnf info nginx 报以下错误,则需要把 /etc/yum.repos.d 中不要的 .repo文件删掉

  

 

 

   删掉不要的 .repo文件后,在执行 dnf info nginx 得到如下信息:

  

 

 

 

2、添加nginx的repo

  > vi /etc/yum.repos.d/nginx.repo

  执行上面这句后,把下面的内容作为nginx.reop的内容进行粘贴保存  

[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的所有版本,执行命令 yum list nginx --showduplicates

  > yum list nginx --showduplicates

  结果如下图:  

 

 

4、安装指定版本的nginx,我这里使用最新的,执行yum -y install nginx-1.22.0 命令

  > yum -y install nginx-1.22.0

  

 

   看到这个表示安装完成,我们查看一下安装目录:

  > whereis nginx

  

 5、启动nginx

  > nginx

  

 

 

 

6、nginx几个操作命令  

nginx #启动

nginx -s stop #停止nginx

nginx -s reload #重启nginx

nginx -c /etc/nginx/nginx.conf #使用指定配置文件启动nginx

nginx -t #检测配置文件是否有错误

nginx -v #查看版本信息

 

 

 

 

 

  参考文章:https://www.cnblogs.com/niewd/p/15035272.html

 

posted @ 2022-06-15 12:54  war3_xiaofeng  阅读(123)  评论(0编辑  收藏  举报