Solved

How RewriteEngine works in Apache web server for Load Balancer

Posted on 2014-11-07
5
74 Views
Last Modified: 2015-04-08
I have following lines in my httpd.conf of a server which is behind a load balancer (AWS ELB)

<VirtualHost *:80>
#for instances behind AWS LoadBalancer
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
## Below you need to use escape character \ before the period's in ELB CNAME. For example, my-test-elb-0000002951\.us-east-1\.elb\.amazonaws\.com
RewriteCond %{HTTP_HOST} !^my_application-1973433045\.eu-west-1\.elb\.amazonaws\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L,NE]
</VirtualHost>

Open in new window


I would like to understand what it does.
0
Comment
Question by:beer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40429927
Please see my answer to your other question for most of the details.  For the rest, see my comments below:
<VirtualHost *:80>
#for instances behind AWS LoadBalancer
RewriteEngine On
# checks to see if the HTTP header X-Forwarded-Proto is equal to the string "http"
RewriteCond %{HTTP:X-Forwarded-Proto} =http
## Below you need to use escape character \ before the period's in ELB CNAME. For example, my-test-elb-0000002951\.us-east-1\.elb\.amazonaws\.com
# check that the requested host is not "my_application-1973433045.eu-west-1.elb.amazonaws.com"
RewriteCond %{HTTP_HOST} !^my_application-1973433045\.eu-west-1\.elb\.amazonaws\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L,NE]
</VirtualHost>

Open in new window

0
 

Author Comment

by:beer9
ID: 40429963
so if my application client.myapplication.com is CNAME to AWS ELB my_application-1973433045.eu-west-1.elb.amazonaws.com then I can can not access my application using my_application-1973433045.eu-west-1.elb.amazonaws.com URL I have to have to use client.myapplication.com ?
0
 

Author Comment

by:beer9
ID: 40429964
same thing if I want to access it via ip of my domain/ELB then that will also not be served?
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40430309
The domain will be served in both cases.  However, the rewrite will only take effect on requests if the host is *not* "my_application-1973433045.eu-west-1.elb.amazonaws.com".
0
 

Author Comment

by:beer9
ID: 40430971
when I access my_application-1973433045.eu-west-1.elb.amazonaws.com then I gets redirected to https://my_application-1973433045.eu-west-1.elb.amazonaws.com/my_application then it shows

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

Open in new window


what is causing it to redirect to https://my_application-1973433045.eu-west-1.elb.amazonaws.com/my_application ?


Thanks!
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question