CentOS 上安装 Nginx

67 阅读1分钟

在 CentOS 上安装 Nginx 的步骤如下:

1. 安装 epel-release

Nginx 可以通过 epel-release 存储库安装。如果你的系统还没有 epel-release,可以通过以下命令安装:

sudo yum install epel-release

2. 安装 Nginx

使用 yum 命令安装 Nginx:

sudo yum install nginx

3. 启动 Nginx

安装完成后,启动 Nginx 服务并设置它开机自启动:

sudo systemctl start nginx
sudo systemctl enable nginx

4. 验证安装

访问你的服务器的公共 IP 地址或域名,应该能够看到 Nginx 的欢迎页面。你可以使用浏览器或者 curl 命令来验证:

curl http://服务器的IP地址

如果安装成功,你应该能够看到 Nginx 的欢迎页面的 HTML 内容。

5. 配置防火墙

如果你的 CentOS 服务器开启了防火墙,确保允许 HTTP(80 端口)和 HTTPS(443 端口)流量通过防火墙:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

现在,Nginx 已经安装在你的 CentOS 服务器上,并且可以通过浏览器访问了。