Skip to content

Instantly share code, notes, and snippets.

@alphabet
Forked from tunght13488/.htaccess
Created November 6, 2018 20:19
Show Gist options
  • Save alphabet/d834620aea889e6e0e337c3f66b9517a to your computer and use it in GitHub Desktop.
Save alphabet/d834620aea889e6e0e337c3f66b9517a to your computer and use it in GitHub Desktop.
htaccess IP whitelisted rule behind load balancer
# 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