-
-
Save alphabet/d834620aea889e6e0e337c3f66b9517a to your computer and use it in GitHub Desktop.
htaccess IP whitelisted rule behind load balancer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: http://www.jonathanquail.com/blog/2012/05/09/restricting-access-to-servers-behind-an-elastic-load-balancer/ | |
# Extract client IP | |
#SetEnvIf REMOTE_ADDR "(.+)" CLIENTIP=$1 | |
# If request is forwarded, use forwarded IP instead | |
SetEnvIf X-Forwarded-For "^([0-9.]+)" CLIENTIP=$1 | |
# If request is not forwarded, set a flag | |
SetEnvIf X-Forwarded-For "^$" is_not_forwarded | |
# Whitelist | |
SetEnvIf CLIENTIP "173.55.53.87" allowed_in | |
SetEnvIf CLIENTIP "72.67.47.197" allowed_in | |
# Rules | |
Order deny,allow | |
Deny from all | |
# Allow whitelisted forwarded IP | |
Allow from env=allowed_in | |
# Allow request which is not forwarded (healthcheck) | |
Allow from env=is_not_forwarded | |
# Remove comment from the following line to let everyone in | |
#Allow from all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment