1.安装 yum install -y nginx
若报错 No package nginx available. 则 执行 vim /etc/yum.repos.d/nginx.repo
若报错 -bash: vim: command not found 则 yum install -y vim
在文件nginx.repo 中写入
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
#baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
再次 yum install -y nginx 即可
2.启动nginx并设置开机启动 systemctl start nginx systemctl enable nginx
3.验证nginx是否启动 ps -ef | grep -v grep | grep nginx
4. 编辑nginx配置文件 vi /etc/nginx/nginx.conf
5.对于yum安装的nginx来说,要想使配置文件的修改生效,需重启nginx systemctl restart nginx 或 nginx -s reload
6. 网页验证nginx是否成功运行:输入IP
7. 当nginx配置正确,一切正常,nginx还是访问不了时,执行 setsebool -P httpd_can_network_connect 1 试试