Nginx同样需要配置额外的yum仓库,才可以使用yum安装

Nginx同样需要配置额外的yum仓库,才可以使用yum安装

1. 安装yum依赖程序
# root执行
yum install -y yum-utils
2. 手动添加,nginx的yum仓库
yum程序使用的仓库配置文件,存放在:/etc/yum.repo.d内。


# root执行
# 创建文件使用vim编辑
vim /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
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. 通过yum安装最新稳定版的nginx
# root执行
yum install -y nginx
4. 启动

# nginx自动注册了systemctl系统服务
systemctl start nginx        # 启动
systemctl restart nginx      # 重启
systemctl stop nginx        # 停止
systemctl status nginx        # 运行状态
systemctl enable nginx        # 开机自启
systemctl disable nginx        # 关闭开机自启

5. 配置防火墙放行
nginx默认绑定80端口,需要关闭防火墙或放行80端口
比较推荐第一种方法,不关闭防火墙的话可能导致无法访问


# 方式1(推荐),关闭防火墙
systemctl stop firewalld        # 关闭
systemctl disable firewalld        # 关闭开机自启

# 方式2,放行80端口
firewall-cmd --add-port=80/tcp --permanent        # 放行tcp规则下的80端口,永久生效
firewall-cmd --reload                            # 重新加载防火墙规则

6. 启动后浏览器输入Linux服务器的IP地址或主机名即可访问
http://192.168.1.2 或 http://centos

至此,Nginx安装配置完成。

7. Nginx的文件路径
1.默认的根目录在: /usr/share/nginx/html
2.配置文件目录在: /etc/nginx/nginx.conf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值