"General socket error" when Nginx behind HAProxy using a unix socket

I use HAProxy in front of nginx for performance reasons, and I seem to be unable to use a unix socket for communication between HAProxy and Nginx.

HAProxy configuration:

backend nginx                                                                                                     
  option forwardfor                                                                                              
  option http-server-close                                                                                        
  server nginx_unix /var/run/nginx-webhook.sock check send-proxy

Nginx config:

server {                                                                                                         
  listen 8080 proxy_protocol;                                                                                   
  listen unix:/var/run/nginx-webhook.sock proxy_protocol;
  ...
}

The socket does exist:

$ ls -lah /var/run/nginx-webhook.sock                                                                               
srw-rw-rw- 1 root root 0 Feb  7 19:29 /var/run/nginx-webhook.sock

This is the error I get from the HAProxy status page:

HAProxy status page screenshot

Mar 17 14:38:42 app01 haproxy[11597]: Server nginx/nginx_unix is DOWN, reason: Socket error, info: "General socket│
 error (No such file or directory)", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0│
 requeued, 0 remaining in queue.

Not sure what's going wrong; the socket does exist after all.


Solution 1:

I had the same problem with Haproxy 1.8.19 on Debian Buster with Varnish 6.0.3 as backend.

For me, the problem come from chroot option in Haproxy configuration :

chroot /var/lib/haproxy

You have two solutions to fix this :

  • Move your's Nginx Unix socket in chroot directory

  • Or disable chroot option, but it's not recommended for security reason.