首先安装EPEL仓库:
sudo yum install epel-release
更新yum缓存:
sudo yum update
安装Nginx:
sudo yum install nginx
创建Nginx官方仓库文件:
sudo vi /etc/yum.repos.d/nginx.repo
添加以下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
安装Nginx:
sudo yum install nginx
启动Nginx服务:
sudo systemctl start nginx
设置开机自动启动:
sudo systemctl enable nginx
检查Nginx状态:
sudo systemctl status 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
在浏览器中访问服务器的IP地址,应该能看到Nginx欢迎页面
或者使用curl命令:
curl http://localhost
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo nginx -t
nginx -v
/etc/nginx/nginx.conf
/etc/nginx/conf.d/default.conf
/usr/share/nginx/html
/var/log/nginx/