Solved

How RewriteEngine works in Apache web server for Load Balancer

Posted on 2014-11-07
5
72 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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