在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
相关推荐
Sumlll_7 小时前
Ubuntu系统下QEMU的安装与RISC-V的测试
linux·ubuntu·risc-v
猫头虎7 小时前
2025最新OpenEuler系统安装MySQL的详细教程
linux·服务器·数据库·sql·mysql·macos·openeuler
晚风吹人醒.9 小时前
SSH远程管理及访问控制
linux·运维·ssh·scp·xshell·访问控制·远程管理
Uncertainty!!10 小时前
Linux多用户情况下个别用户输入密码后黑屏
linux·远程连接
necessary65310 小时前
使用Clion查看linux环境中的PG源码
linux·运维·服务器
小猪佩奇TONY12 小时前
Linux 内核学习(14) --- linux x86-32 虚拟地址空间
linux·学习
Lam㊣12 小时前
Centos 7 系统docker:更换镜像源
linux·docker·centos
FL162386312912 小时前
win11+WSL+Ubuntu-xrdp+远程桌面闪退+黑屏闪退解决
linux·运维·ubuntu
石头53012 小时前
Kubernetes监控全栈解决方案:从零搭建Prometheus+Grafana监控体系
linux
ha204289419412 小时前
Linux操作系统学习记录之---TcpSocket
linux·网络·c++·学习