Nginx的安装与配置
2023/8/26
Nginx的安装与配置
本文主要讲解通过yum在线安装Nginx的方法
添加Yum源
配置官方源
执行如下命令
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
查看源配置
yum repolist
安装与测试
执行安装
yum install nginx -y
验证安装版本
nginx -v
配置开机自启动
# 配置开机自启动
systemctl enable nginx
# 启动服务
systemctl start nginx
防火墙配置
配置防火墙开放端口,或将防火墙关闭
# 关闭防火墙
systemctl stop firewalld
# 永久禁用防火墙
systemctl disable firewalld
# 查看防火墙状态
systemctl status firewalld
验证测试
直接访问IP,出现如下界面,表示安装成功。

Ngix配置文件
存放路径
Nginx默认主配置文件
/etc/nginx/nginx.confNginx html默认存放目录
/usr/share/nginx/htmlNginx默认主页路径
/usr/share/nginx/html/index.html
配置文件的修改
Nginx常用命令
# 启动Nginx
systemctl start nginx
# 停止Nginx
systemctl stop nginx
# 重载Nginx
systemctl reload nginx
# 重启Nginx
systemctl restart nginx
# 查询Nginx运行状态
systemctl status nginx
# 查询Nginx进程
ps -ef |grep nginx
# 查询Nginx监听端口
netstat -lntup |grep nginx
# 卸载Nginx
yum -y remove nginx