Php – Load balance PHP-FPM with HAProxy resulting in service unavailable

debianhaproxyload balancingPHPphp-fpm

I need to load balance PHP-FPM with two backend servers with HAProxy (with Apache running on those backend servers as well).

I have this frontend:

frontend fr_fpm
  bind *:9000
  mode tcp
  default_backend bk_fpm

And I have this backend:

backend bk_fpm
  mode tcp
  balance leastconn
  server app0.test.cyberfusion.cloud 10.10.0.4:9000
  server app1.test.cyberfusion.cloud 10.10.0.5:9000

I've set PHP-FPM to bind to 0.0.0.0 and I can telnet the port. I've set ProxyPass in the Apache configuration to the load balancer.

I see the requests coming in on HAProxy:

Nov 18 15:27:51 public-lb0 haproxy[3598]: 10.10.0.5:37652 [18/Nov/2018:15:27:51.995] fr_fpm bk_fpm/app0.test.cyberfusion.cloud 1/0/0 0 SD 5/0/0/0/0 0/0

Traffic goes out when the request comes in:

root@public-lb0:/etc/haproxy# tcpdump -i any -n dst port 9000
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
15:32:04.353294 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [S], seq 372704667, win 29200, options [mss 1460,sackOK,TS val 777738 ecr 0,nop,wscale 6], length 0
15:32:04.353394 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [.], ack 1286887776, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 0
15:32:04.353423 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 0:16, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 16
15:32:04.353451 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 16:1134, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 1118
15:32:04.353465 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 1134:1142, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 8
15:32:04.353477 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 1142:1150, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 8
15:32:04.354064 IP 10.10.0.174.46364 > 10.10.0.5.9000: Flags [S], seq 4004335738, win 29200, options [mss 1460,sackOK,TS val 4037378 ecr 0,nop,wscale 6], length 0
15:32:04.354155 IP 10.10.0.174.46364 > 10.10.0.5.9000: Flags [.], ack 1976670206, win 457, options [nop,nop,TS val 4037378 ecr 777739], length 0
15:32:04.354251 IP 10.10.0.174.46364 > 10.10.0.5.9000: Flags [P.], seq 0:1150, ack 1, win 457, options [nop,nop,TS val 4037378 ecr 777739], length 1150
15:32:04.354644 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [F.], seq 1150, ack 2, win 457, options [nop,nop,TS val 777739 ecr 4037379], length 0

Unfortunately, I get a service unavailable, unless both the HTTP traffic and PHP-FPM request arrive at the same server (or so it seems).

Am I doing something wrong in my config?

Best Answer

The issue seems to have been fixed by replacing listen 0.0.0.0:9000 to listen 9000.