添加 EPEL 仓库:
sudo yum install epel-release
安装 Nginx:
sudo yum install nginx
启动 Nginx 服务:
sudo systemctl start nginx
设置开机自启:
sudo systemctl enable nginx
创建 Nginx 官方仓库文件:
sudo vi /etc/yum.repos.d/nginx.repo
添加以下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
安装 Nginx:
sudo yum install nginx
启动并启用服务:
sudo systemctl start nginx
sudo systemctl enable nginx
检查 Nginx 状态:
sudo systemctl status nginx
测试 Nginx 是否运行: 在浏览器访问服务器的 IP 地址,应该能看到 Nginx 欢迎页面。
配置防火墙(如果启用了 firewalld):
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo nginx -t
/etc/nginx/nginx.conf
/etc/nginx/conf.d/default.conf
/usr/share/nginx/html
/var/log/nginx/access.log
/var/log/nginx/error.log
安装完成后,您可以根据需要修改配置文件来设置虚拟主机、SSL 证书等高级配置。