Solved

How RewriteEngine works in Apache web server for Load Balancer

Posted on 2014-11-07
5
77 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 51

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 51

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
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 …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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