在centos7下用nginx+ tomcat搭建负载均衡集群。ng ,tomcat都是启动的,分别都可以访问,但是配置后无法通过ng访问tomcat。查看/var/log/nginx/error.log 大量报错:
2020/08/05 14:50:23 [crit] 23141#23141: *1 connect() to [::1]:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.80.74, server: localhost, request: "GET /index.html HTTP/1.1", upstream: "http://[::1]:8080/index.html", host: "192.168.80.86"
2020/08/05 14:50:23 [warn] 23141#23141: *1 upstream server temporarily disabled while connecting to upstream, client: 192.168.80.74, server: localhost, request: "GET /index.html HTTP/1.1", upstream: "http://[::1]:8080/index.html", host: "192.168.80.86"
2020/08/05 14:50:23 [error] 23141#23141: *1 no live upstreams while connecting to upstream, client: 192.168.80.74, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://localhost/favicon.ico", host: "192.168.80.86", referrer: "http://192.168.80.86/index.html"
首先,网上大多认为是用户问题。将nginx.conf改成了root用户也无法解决。
进一步搜索发现问题的症结指向了selinux。linux的一个安全机制。
1)尝试临时关闭 setenforce 0
有效
2)进一步永久关闭:
- vi /etc/selinux/config 将 enforcing改成disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
- reboot 重启服务器
再次访问,成功