?
Solved

How RewriteEngine works in Apache web server for Load Balancer

Posted on 2014-11-07
5
Medium Priority
?
87 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 2000 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 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