6

In nginx it is fairly simple to configure it to proxy unix .sock files

Eg:

upstream bla {
      server unix:///home/sam/Source/bla/tmp/sockets/thin1.sock;
      server unix:///home/sam/Source/bla/tmp/sockets/thin2.sock;
 }

Is there a similar syntax in haProxy to enable balancing local .sock filew

0

3 Answers 3

16

Short answer: Yes, since version 1.5.

Let's have a look at server keyword arguments documentation:

<address> is the IPv4 or IPv6 address of the server. Alternatively, a
          resolvable hostname is supported, but this name will be resolved
          during start-up. Address "0.0.0.0" or "*" has a special meaning.
          It indicates that the connection will be forwarded to the same IP
          address as the one from the client connection. This is useful in
          transparent proxy architectures where the client's connection is
          intercepted and haproxy must forward to the original destination
          address. This is more or less what the "transparent" keyword does
          except that with a server it's possible to limit concurrency and
          to report statistics. Optionally, an address family prefix may be
          used before the address to force the family regardless of the
          address format, which can be useful to specify a path to a unix
          socket with no slash ('/'). Currently supported prefixes are :
                - 'ipv4@'  -> address is always IPv4
                - 'ipv6@'  -> address is always IPv6
                - 'unix@'  -> address is a path to a local unix socket
                - 'abns@'  -> address is in abstract namespace (Linux only)
          Any part of the address string may reference any number of
          environment variables by preceding their name with a dollar
          sign ('$') and optionally enclosing them with braces ('{}'),
          similarly to what is done in Bourne shell.

So you may specify path to unix socket with leading slash, or explicitly prepend address family prefix:

server nginx1 /run/nginx/default.sock
server nginx2 [email protected]
3

As quanta said it need IPv4 address, but with using socat to relay unix scoket to TCP maybe you can use HAProxy to that.

socat TCP-LISTEN:1234,reuseaddr,fork UNIX-CLIENT:/tmp/foo
3
  • I would change the backend (thin server?) to listen on a TCP socket (localhost:port) instead of Unix socket.
    – quanta
    Aug 15, 2012 at 5:05
  • Yes I agree that it would be the best, but if it can't listen to TCP then you have to trick it to do so.
    – Stone
    Aug 15, 2012 at 5:07
  • haproxy is high-performance server, socat isn't.
    – poige
    Jun 28, 2015 at 9:27
0

AFAIK, HAProxy doesn't support it. According to the document, you must specify an IPv4 or IPv6 (or hostname) of the server.

2
  • This is wrong. It does.
    – poige
    Jun 28, 2015 at 9:24
  • I couldn't get haproxy 1.9 to work with "server www-backend "unix@/var/run/docker.sock" (also tried with unix@ prefix) despite docs saying it should (cbonte.github.io/haproxy-dconv/1.9/…). I tried this. Using socat and that port as the backend worked but seems flaky.
    – jamshid
    Jun 26, 2019 at 17:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .