Search code examples
haproxyno-response

How can I close haproxy frontend connections coming from unknown hosts?


Now I am using nginx to close connections from unknown hosts and return 444 "no response"

How do I achieve the same with haproxy which is in front of nginx (saving the extra step between haproxy and nginx)

current nginx config:

server {
  # Close connection for unrecognized hosts (444 no response)
  listen 80 default_server;
  listen [::]:80 default_server;

  return 444;
}

Solution

  • This can be achieved using "silent-drop"

    acl host_example req.hdr(host) -i example.com
    http-request silent-drop if not host_example
    

    https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-request%20silent-drop https://www.haproxy.com/blog/introduction-to-haproxy-acls/#using-acls-to-block-requests