Assuming that you want requests to http://example.com to serve your website, and requests to http://188.8.131.52 to be explicitly dropped you have 2 main options that I am aware of.
1) is to use mod_security module and the
drop target. A configuration like this;
SecRule REMOTE_ADDR "^\d" id:'1234',drop,phase:1
<Directory /var/www/example.com >
AllowOverride FileInfo Options
Allow from all
returns the website, if you go to http://example.com
# wget -O- http://example.com
--2018-03-09 15:35:35-- http://example.com/
Resolving example.com (example.com)... 127.0.0.1
Connecting to example.com (example.com)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24 [text/html]
Saving to: ‘STDOUT’
and if you try to go to the default site via ip http://127.0.0.1
# wget -O- http://127.0.0.1
--2018-03-09 15:35:28-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... No data received.
The connection is dropped
2) The second option is to use the
string module for iptables and drop connections with a header matching
iptables -A INPUT -m string --string "Host: 184.108.40.206" -j DROP
(I didn't test that iptables rules...so you would have to check the docs for the correct incantation...)
However I think the mod_security option is simpler