i'm trying to use HAProxy to redirect on different nodejs webserver working on three different port. What i want is that when i try to open /node1 HAProxy redirect me to that web server. This is HAProxy configuration:

frontend dispatcher
    mode http
    bind *:80
    acl node_serv1 url_beg /node1
    acl node_serv2 url_beg /node2
    acl node_serv3 url_beg /node3

    use_backend backend_1 if node_serv1
    use_backend backend_2 if node_serv2
    use_backend backend_3 if node_serv3

backend backend_1
    mode http
    balance roundrobin
    option  httpchk
    server web01 check

backend backend_2
    mode http
    balance roundrobin
    option  httpchk
    server web02 check

backend backend_3
    mode http
    balance roundrobin
    option  httpchk
    server web03 check

All three nodejs webserver are working but when i try to start haproxy i get this error:

Starting haproxy: [ALERT] 111/105652 (27208) : Starting frontend dispatcher: cannot bind socket []

looking on web someone suggest to add this property


on /etc/sysctl.conf

but the error persists and HAProxy doesn't start. What's wrong in my configuration?

  • 2
    Could you show the ouput of netstat -anp | grep ":80"? Besides: Do you know what setting net.ipv4.ip_nonlocal_bind to 1 does? (I doubt it's needed in your environment..) – gf_ Apr 21 '16 at 9:25

The most probable cause is that some other process is already bound to port 80 (e.g. another webserver).

Before starting haproxy I would suggest to check if port 80 is free to bind

nestat -anp | grep ":80"

If result is not empty than some process already "took" port 80 and your haproxy won't be able to bind to it (especially when you try to bind on all interfaces). Some solution is to stop this process, but this is up to you to verify if that is feasible, as there might another webpage running there.

Another cause is that you try to start the process as non-root user. Non-root users are usually not allowed to bind to privileged ports (with number lower than 1024).

  • this is the output of netstat: tcp 0 0 :::80 :::* LISTEN - – ntrax Apr 21 '16 at 9:56
  • are you sure this is full output? If yes then you launch the command as non-root user. Nevertheless there is something listening on port 80 already and haproxy cannot bind to the port – M.B. Apr 21 '16 at 10:10
  • this is the full output with sudo tcp 0 0 :::80 :::* LISTEN 4788/httpd – ntrax Apr 21 '16 at 10:43
  • 2
    As I mentioned before. There is another process bound to the port 80. In this case it is apache server. In order to make your haproxy work you must stop apache first. – M.B. Apr 21 '16 at 10:51
  • Great replica! :) – gf_ Apr 21 '16 at 12:32

Just add this line to `/etc/sysctl.conf' file

net.ipv4.ip_nonlocal_bind = 1

then run this command

sysctl -p

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.