centos yum 安装 配置 nginx

查看现有安装 nginx 版本

nginx -v

结果:nginx version: nginx/1.14.1
移除已安装nginx

yum remove nginx -y
rm -rf /etc/nginx/

安裝 NGINX 穩定或最新版本

安装 yum 的套件

yum install yum-utils -y

新增nginx官方仓库

vim /etc/yum.repos.d/nginx.repo
# 穩定版
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
module_hotfixes=true

# 最新版
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=0
module_hotfixes=true

切换使用 nginx-stable 稳定版:

yum-config-manager --enable nginx-stable

查看nginx 仓库版本

yum info nginx
结果:
Available Packages
Name         : nginx
Epoch        : 1
Version      : 1.20.1
Release      : 1.el8.ngx
Architecture : x86_64
Size         : 819 k
Source       : nginx-1.20.1-1.el8.ngx.src.rpm
Repository   : nginx-stable
Summary      : High performance web server
URL          : https://nginx.org/
License      : 2-clause BSD-like license
Description  : nginx [engine x] is an HTTP and reverse proxy server, as well as
             : a mail proxy server.

安装模块

安装nginx

yum install -y nginx

查看安装的 nginx 版本

nginx -v
结果: nginx version: nginx/1.20.1

此时已经成功可以使用了

服务部分命令

启动 nginx

systemctl start nginx.service

设置 nginx 开机自启动

systemctl enable nginx.service

关闭 nginx

systemctl stop nginx.service

重启 nginx

systemctl restart nginx.service
nginx操作命令
nginx -s reload|reopen|stop|quit  #重新加载配置|重启|停止|退出 nginx
nginx检测配置是否正确
nginx -t   #测试配置是否有语法错误
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容