Skip to main content

腾讯云centerOS 安装 nginx

yum -y update

升级系统到最新

yum install nginx
#启动nginx
systemctl start nginx
#开机启动nginx
systemctl enable nginx
#查看运行状态
systemctl status nginx

此刻理论上通过ip地址能访问到nginx服务器,但事实上还是无法访问,

为了网络安全centerOS内置的防火墙不会开放http的端口;

想要访问到服务器我们有两种方式,1:关闭防火墙;2:公开80端口

  • 公开80端口 第一步设置公开您的80端口
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    # 也可通过以下 开启https和http服务
    # firewall-cmd --zone=public --add-service=http --permanent
    # firewall-cmd --zone=public --add-service=https --permanent
    第二步:添加上述防火墙规则后,使用以下命令重新加载防火墙服务
    firewall-cmd --reload
    第三步:
  • 关闭防火墙
    systomctl stop firewalld