Centos7 中Nginx的安装与配置

 

 

安装与配置

1.安装nginx

yum intsall nginx
启动服务
sudo systemctl start nginxsudo firewall-cmd --permanent --zone=public --add-service=http 容许http通讯 sudo firewall-cmd --permanent --zone=public --add-service=https  容许https通讯 sudo firewall-cmd --reload 从新加载配置

2.配置

在 /etc/nginx/conf.d 目录中新建一个my.conf文件,在此以前先将nginx.conf 配置文件中的server节点注释掉nginx

server {
        listen 80; #映射端口 location / { proxy_pass http://localhost:5000; #监听端口 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

3.使用新配置启动nginx

执行这两个命令中的任一个重置nginx网络

 nginx -s reload  从新加载配置文件
 systemctl  nginx restart  重启nginx

4.访问网站

此时经过80端口访问网站应该是一切正常,但不凡意外发生ide

异常状况502

进入 /var/log/nginx/ 目录中查看错误日志,若是是如下错误,能够尝试用下面的方法解决学习

getsebool -a |grep httpd_can_network_connect //检查http网络访问权限状况

咱们能够看到它是关闭状态的网站

执行 setsebool -P httpd_can_network_connect 1 //开启网络访问权限

开启后 http_can_network_connect 状态为onspa

此时在访问应该不会再有问题了,此文仅为学习时记录,我本身重现了三次,应该是没什么问题的。最后 跟jesse 一块儿学习.Net Core 。
相关文章
相关标签/搜索