我使用upstream
andproxy
进行负载平衡。
[[email protected] ~]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
upstream sites {
server 192.168.1.237:8080;
server 192.168.1.240:8080;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://sites;
}
}
}
当我在浏览器中打开 192.168.1.135 时,它告诉我,«网站暂时不可用»。
来自 192.168.1.135 的所有 ping 均正常工作:
PING 192.168.1.237 (192.168.1.237) 56(84) bytes of data.
64 bytes from 192.168.1.237: icmp_seq=1 ttl=64 time=0.803 ms
64 bytes from 192.168.1.237: icmp_seq=2 ttl=64 time=0.329 ms
64 bytes from 192.168.1.237: icmp_seq=3 ttl=64 time=0.676 ms
64 bytes from 192.168.1.237: icmp_seq=4 ttl=64 time=0.579 ms
PING 192.168.1.240 (192.168.1.240) 56(84) bytes of data.
64 bytes from 192.168.1.240: icmp_seq=1 ttl=64 time=0.607 ms
64 bytes from 192.168.1.240: icmp_seq=2 ttl=64 time=0.264 ms
64 bytes from 192.168.1.240: icmp_seq=3 ttl=64 time=0.358 ms
64 bytes from 192.168.1.240: icmp_seq=4 ttl=64 time=0.253 ms
当我将浏览器指向http://192.168.1.237:8080或http://192.168.1.240:8080时,它们会成功打开。
nginx 错误日志
2016/04/13 18:36:59 [crit] 5427#0: *20 connect() to 192.168.1.240:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.1.15, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.1.240:8080/", host: "192.168.1.135"
2016/04/13 18:36:59 [crit] 5427#0: *20 connect() to 192.168.1.237:8080 failed (13: Permission denied) while connecting to upstream, client: 192.168.1.15, server: _, request: "GET / HTTP/1.1", upstream: "http://192.168.1.237:8080/", host: "192.168.1.135"
什么地方出了错?谢谢你。
工作配置部分:
如果 SELinux 的问题不会消失,您需要打开
httpd_can_network_connect
指令: