yum仓库的搭建与Nginx的安装

安装前提:
nginx需要配置额外的yum仓库,才可使用yum安装,安装nginx 需要root身份

一、yum仓库的搭建

1. 安装yum依赖程序

yum install -y yum-utils

2. 手动添加,nginx的yum仓库

yum程序使用的仓库配置文件,存放在: /etx/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
gpgkey=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

二nginx的安装

1.安装Nginx

# root执行
yum install -y nginx

2.启动

[root@localhost ~]# systemctl start nginx    #启动
[root@localhost ~]# systemctl stop nginx     #停止
[root@localhost ~]# systemctl status nginx   #状态查询
[root@localhost ~]# systemctl enable nginx   #开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# systemctl disable nginx   #关闭开启自启
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.```
## 3.配置防火墙
Nginx默认绑定80端口,需要关闭防火请或者放行80端口

3.防火墙

1】方式1: 关闭防火请(推荐)
[root@localhost ~]# systemctl stop firewalld    #关闭防火墙
[root@localhost ~]# systemctl disable firewalld   #关闭开机自启
【2】放行80端口
Firewall-cmd --add port=80/tcp --permanent    # 放行top规则下的80端口,永久生效
firewall-cmd --reload   #重新加载防火请规则

4.启动

启动后浏览器输入linux服务器IP地址或者主机名即可访问
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_46268244/article/details/129339640