腾讯云OpenCloudOS 9.4安装nginx?

在腾讯云 OpenCloudOS 9.4 上安装 Nginx,推荐使用系统自带的 dnf 包管理器(OpenCloudOS 基于 RHEL/CentOS 生态),这样能确保软件源兼容且获得安全更新。以下是标准安装步骤:

1. 更新系统包索引

sudo dnf update -y

2. 安装 EPEL 源(可选但推荐)

虽然官方源通常已包含 Nginx,但某些版本可能需额外启用 EPEL 以获取最新稳定版:

sudo dnf install epel-release -y

3. 安装 Nginx

sudo dnf install nginx -y

💡 提示:若官方源中 Nginx 版本较旧(如 1.14/1.16),可考虑从 Nginx 官方仓库 添加第三方源以获得最新版(如 1.24+)。但需注意:OpenCloudOS 对非官方源的兼容性需自行验证。

4. 启动并设置开机自启

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

5. 配置防火墙(腾讯云安全组 + 本地防火墙)

  • 本地防火墙(firewalld):
    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --permanent --add-service=https
    sudo firewall-cmd --reload
  • 腾讯云控制台:务必在实例的【安全组】规则中放行 TCP 80 和 443 端口,否则外部无法访问。

6. 验证安装

访问 http://<您的公网IP>http://<服务器内网IP>,应看到 Nginx 默认欢迎页。


附加建议

  • 配置文件位置/etc/nginx/nginx.conf(主配置)、/etc/nginx/conf.d/(站点配置)
  • 日志路径/var/log/nginx/
  • 重启生效:修改配置后执行 sudo nginx -t 测试语法,再用 sudo systemctl reload nginx 重载

如需部署 HTTPS 或虚拟主机,可进一步编辑 /etc/nginx/conf.d/ 下的站点配置文件。需要具体示例可提供需求场景。

未经允许不得转载:CLOUD技术博 » 腾讯云OpenCloudOS 9.4安装nginx?