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

1.7k Views Asked by At

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;
}
2

There are 2 best solutions below

0
Ejez On BEST ANSWER

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

1
Rangeesh On

Ejez you can either accept connections coming from known ip's are block connections of particular ip's in frontend of haproxy.

ref code:

  • allowed known ip's
acl network_allowed src 20.30.40.50 20.30.40.40
use_backend allowed_backend if network_allowed

or

  • block certain ip's only
acl is-blocked-ip src 192.0.2.11 192.0.2.12 192.0.2.18
http-request deny if is-blocked-ip

ref: