我正在尝试在 Red Hat 7.1 机器上配置 haproxy(haproxy 1.5.4)
代理一些nodejs实例。
如果我尝试访问端口 80(haproxy 前端),它会返回错误 503;如果我尝试访问端口 3000(节点应用服务),它会返回 ok
这是我的 haproxy 配置:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend main *:80
default_backend app
backend app
balance roundrobin
server app1 127.0.0.1:3000 check
欢迎任何指导。
答案1
感谢大家的帮助,问题出在 selinux 上。有关此线程的更多详细信息:CentOS 7 上 systemctl 与 Haproxy 的奇怪交互
我需要做的就是运行这个命令:
sudo semanage port --add --type http_port_t --proto tcp 3000
并将我的配置文件更改为:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 1000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend main 0.0.0.0:80
default_backend app
backend app
balance roundrobin
server app1 127.0.0.1:3000 check