Block IP addresses in .htaccess (via proxy server or load balancer)

less than 1 minute read

When the server is accessed via a proxy server or load balancer, the connection source IP address is that of those devices, so the normal block writing method cannot be used.

.htaccess


order allow,deny
allow from all
deny from 255.255.255.255

In that case, use “X-Forwarded-For”.

.htaccess


SetEnvIf X-Forwarded-For “255\.255\.255\.255” denied_ip
 
order allow,deny
allow from all
deny from env=denied_ip

Remarks

This article is a migration article from the blog “Technical Notes for Chores Engineers”. The previous blog will be deleted.