.htaccess RewriteCond for maintanace page behind Elastic Load Balancer

Viewed 282

My web server is behind AWS Elastic load-balancer and the Listener protocol for the ELB is TCP for 80 and 443 (not HTTP/HTTPS).

I need to add a conditional redirect to my .htaccess in order to display a maintenance page whenever we take the site offline for maintenance except for my IP address.

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteCond %{REMOTE_HOST} !^1.1.1.1
RewriteRule $ maintenance.html [NC,L]

However, because my web server is behind a load balancer, REMOTE_ADDR is resolved to the internal IP address of the Load Balance server.

%{HTTP:X-FORWARDED-FOR} instead of %{REMOTE_HOST} doesn't work for me, I think that is because of the TCP protocol used instead of HTTP. How can I get the client IP address? or Do I need to do any changes on apache configuration or on ELB?

Apache Configuration for ssl

<VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile  /etc/apache2/ssl/cert.cer
        SSLCertificateKeyFile /etc/apache2/ssl/cert.key
        SSLCACertificateFile /etc/apache2/ssl/cacert.cer
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
</VirtualHost>
<Directory /usr/lib/cgi-bin>
        SSLOptions +StdEnvVars
</Directory>
<Directory /var/www/html>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride all
        Order deny,allow
        Deny from all
        Allow from all
</Directory>
0 Answers
Related