参考:https://www.jianshu.com/p/b1f573ca50c7

跟着做到,配置nginx访问dotnet core网站时,报错了。

错误如下所示——

Linux CentOS 7 下dotnet core webpai + nginx 部署_nginx

 

 

 查看nginx的错误日志: cat /var/log/nginx/error.log | more

Linux CentOS 7 下dotnet core webpai + nginx 部署_官网_02

 

 

 再查看系统的nginx相关的审计日志 cat /var/log/audit/audit.log | grep nginx | grep denied

Linux CentOS 7 下dotnet core webpai + nginx 部署_官网_03

 

 

 bing查找关键字——.netcore webapi nginx permission denied

stackoverflow上找到了可用信息:https://stackoverflow.com/questions/36315637/permission-denied-connecting-to-upstream

终于找到了问题的原因:SELinux

在官网找到了更加详细的描述:

Linux CentOS 7 下dotnet core webpai + nginx 部署_centos_04

 

 

RHEL和CentOS类的服务器,SELinux默认时开启的。

接着下面还有一段描述:

Linux CentOS 7 下dotnet core webpai + nginx 部署_centos_05

 

 

SELinux在RHEL和CentOS系统中,默认的标签是httpd_t,这个安全程序会阻止location代理(英语水平比较烂,大概的意思就是这样)

官网给出了临时关闭SELinux的指令【# semanage permissive -a httpd_t】

当关闭后,再在宿主机上进行访问,发现正常了。

还要注意的是.net core webapi 默认开了https的访问方式,需要在nginx代理中配置这个https的访问地址,否则还是无法访问成功。

Linux CentOS 7 下dotnet core webpai + nginx 部署_nginx_06

 

 下面是我的nginx.conf配置

Linux CentOS 7 下dotnet core webpai + nginx 部署_linux_07

 

 当然了,这个SELinux还要不能关闭的,根据官网的说明进行相应的配置即可,这里不多说了。

 

资源:

https://www.nginx.com/blog/using-nginx-plus-with-selinux/

https://www.jianshu.com/p/b1f573ca50c7

 

(完)