<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=HAProxy_Restrict_by_IP_Address</id>
		<title>HAProxy Restrict by IP Address - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=HAProxy_Restrict_by_IP_Address"/>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=HAProxy_Restrict_by_IP_Address&amp;action=history"/>
		<updated>2026-06-04T02:44:56Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://briansnelson.com/index.php?title=HAProxy_Restrict_by_IP_Address&amp;diff=1031&amp;oldid=prev</id>
		<title>Brian: Created page with &quot;==HAProxy Restrict by IP Address==  As with any proxy service, you want to block bad ips before they get to the backend servers.  With haproxy you can block ips really easy....&quot;</title>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=HAProxy_Restrict_by_IP_Address&amp;diff=1031&amp;oldid=prev"/>
				<updated>2019-12-12T21:24:53Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==HAProxy Restrict by IP Address==  As with any proxy service, you want to block bad ips before they get to the backend servers.  With haproxy you can block ips really easy....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==HAProxy Restrict by IP Address==&lt;br /&gt;
&lt;br /&gt;
As with any proxy service, you want to block bad ips before they get to the backend servers.  With haproxy you can block ips really easy.&lt;br /&gt;
&lt;br /&gt;
Add the following to your haproxy configuration file&lt;br /&gt;
&lt;br /&gt;
 vim /etc/haproxy/haproxy.cfg&lt;br /&gt;
&lt;br /&gt;
Add the following to your frontend, are blocking via x-forwarded-for and direct ip access, we do this now so you don't have to later if you decided to use cloudflare or another proxy later&lt;br /&gt;
&lt;br /&gt;
  # Blacklist IP list&lt;br /&gt;
  acl is-blacklisted-ip hdr_ip(x-forwarded-for,1) -f /etc/haproxy/blacklist.txt&lt;br /&gt;
  acl is-blacklisted-ip src -m ip -f /etc/haproxy/blacklist.txt&lt;br /&gt;
  http-request deny if is-blacklisted-ip&lt;br /&gt;
&lt;br /&gt;
Save then add the blacklist-agent.txt file.&lt;br /&gt;
&lt;br /&gt;
 vim /etc/haproxy/blacklist.txt&lt;br /&gt;
&lt;br /&gt;
Add some ips to the block list file, you can add lot, you can even block entire countries with this method&lt;br /&gt;
&lt;br /&gt;
 192.168.0.1&lt;br /&gt;
&lt;br /&gt;
Save and check your configuration&lt;br /&gt;
&lt;br /&gt;
 service haproxy check&lt;br /&gt;
&lt;br /&gt;
You are looking for&lt;br /&gt;
&lt;br /&gt;
'''Configuration file is valid'''&lt;br /&gt;
&lt;br /&gt;
Next restart or start the server to start blocking by ip address&lt;br /&gt;
&lt;br /&gt;
 service haproxy restart/start&lt;/div&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	</feed>