在CentOS上安装Nginx服务

配置EPEL源:首先,你需要安装EPEL源,这是一个为RHEL和CentOS提供额外软件包的存储库。你可以通过运行以下命令来安装EPEL源:

bash 复制代码
sudo yum install -y epel-release
sudo yum -y update

安装Nginx:接下来,你可以通过yum命令来安装Nginx:

bash 复制代码
sudo yum install -y nginx

安装成功后,你可以在以下位置找到默认的网站目录和配置文件:

  • 默认的网站目录:/usr/share/nginx/html
  • 默认的配置文件:/etc/nginx/nginx.conf
  • 自定义配置文件目录:/etc/nginx/conf.d/

开启端口:如果你的服务器打开了防火墙,你需要运行以下命令,打开80和443端口1

bash 复制代码
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

操作Nginx:你可以通过以下命令来启动、停止、重启Nginx,以及查看Nginx的状态:

bash 复制代码
# 启动 Nginx
systemctl start nginx
# 停止Nginx
systemctl stop nginx
# 重启Nginx
systemctl restart nginx
# 查看Nginx状态
systemctl status nginx
# 启用开机启动Nginx
systemctl enable nginx
# 禁用开机启动Nginx
systemctl disable nginx
相关推荐
maomi_952641 分钟前
操作系统之EXT文件系统
linux·服务器
伤不起bb4 小时前
MySQL 高可用
linux·运维·数据库·mysql·安全·高可用
tmacfrank7 小时前
网络编程中的直接内存与零拷贝
java·linux·网络
QQ2740287569 小时前
Soundness Gitpod 部署教程
linux·运维·服务器·前端·chrome·web3
qwfys2009 小时前
How to configure Linux mint desktop
linux·desktop·configure·mint
南方以南_9 小时前
Ubuntu操作合集
linux·运维·ubuntu
冼紫菜10 小时前
[特殊字符]CentOS 7.6 安装 JDK 11(适配国内服务器环境)
java·linux·服务器·后端·centos
Chuncheng's blog11 小时前
RedHat7 如何更换yum镜像源
linux
爱莉希雅&&&11 小时前
shell脚本之条件判断,循环控制,exit详解
linux·运维·服务器·ssh
wei_work@12 小时前
【linux】Web服务—搭建nginx+ssl的加密认证web服务器
linux·服务器·ssl