在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
相关推荐
提笔惊蚂蚁38 分钟前
终端VS命令解释器(Linux & Windows)
linux·运维·windows
Nimsolax1 小时前
Linux文件fd
linux
·云扬·1 小时前
【Bug】CentOS 7 使用vim命令报错vim: command not found
centos·vim·bug
tb_first2 小时前
k8sday13数据存储(1.5/2)
linux·运维·服务器·云原生·容器·kubernetes
逢生博客3 小时前
Ubuntu 安装 gvm 管理 Go 语言开发环境
linux·ubuntu·golang·gvm
多吃蔬菜!!!4 小时前
vscode 搭建C/C++开发环境搭建(linux)
linux·c语言·c++
李李李li5 小时前
Ubuntu 22.04 安装tensorrt
linux·tensorrt
phoenix09816 小时前
Linux入门DAY29
linux·运维
入秋7 小时前
Linux服务器安装部署 Nginx、Redis、PostgreSQL、Docker
linux·前端
Mr. Cao code7 小时前
使用Tomcat Clustering和Redis Session Manager实现Session共享
java·linux·运维·redis·缓存·tomcat