添加EPEL仓库(如果尚未添加):
sudo yum install epel-release
安装Nginx:
sudo yum install nginx
启动Nginx服务:
sudo systemctl start nginx
设置开机自启:
sudo systemctl enable nginx
如果需要最新稳定版而非EPEL仓库中的版本:
添加Nginx官方仓库:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装Nginx:
sudo yum install nginx
启动并启用服务(同上)
检查Nginx版本:
nginx -v
检查服务状态:
systemctl status nginx
测试访问: 在浏览器中访问服务器IP地址,应该能看到Nginx欢迎页面。
如果启用了防火墙,需要开放HTTP(80)和HTTPS(443)端口:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
/etc/nginx/nginx.conf
/etc/nginx/conf.d/default.conf
/usr/share/nginx/html
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo nginx -t
通过以上步骤,您应该能够在CentOS 7系统上成功安装并运行Nginx服务。