# Mod\_proxy, mongrel, redirect issue

**URL:** <https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411>\
**Category:** Mongrel\
**Created:** [August 20, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411 "2008-08-20T18:47:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Cavagnolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@Jeremy\_Cavagnolo](https://www.ruby-forum.com/u/Jeremy_Cavagnolo)\
**Post date:** [August 20, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411/1 "2008-08-20T18:47:14Z")

</div>

Hello,

I am configuring apache 2.2 to serve my rails app through mongrel at  
the root of my server. First, I redirect all http traffic to https  
with the following:

ServerName emiliano

NameVirtualHost \*:80  
\<VirtualHost \*:80\>  
RedirectPermanent / [https://emiliano](https://emiliano) #this server is only accessed  
internally

Inside the \<VirtualHost \*:443\> section, I have the following  
configuration, which seems extremely standard:

\<Proxy balancer://mongrel\>  
BalancerMember [http://localhost:8000](http://localhost:8000)  
BalancerMember [http://localhost:8001](http://localhost:8001)  
BalancerMember [http://localhost:8002](http://localhost:8002)

ProxyRequests Off  
\<Proxy \*\>  
Order deny,allow  
Allow from all

ProxyPass /stylesheets !  
ProxyPass /javascripts !  
ProxyPass /images !  
ProxyPass / balancer://mongrel/  
ProxyPassReverse / balancer://mongrel/  
ProxyPreserveHost On

When I point my browser to “[https://emiliano](https://emiliano)” I get the login page  
that I expect. When I submit the login form the authorization is  
properly processed (I checked the access log). However, my browser is  
then directed to [https://emilianousers/home](https://emilianousers/home) (note the missing “/”  
between hostname and ‘users’) which of course cannot be found. If I  
manually insert the slash I am properly directed to the user home  
page. I can click on links all day long and everything works, but  
when I try to submit any form, the form is processed properly, but the  
same issue with the missing slash returns.

I have tried removing the proxy balancer and going directly to the  
mongrel instance, but I get the same behavior. I have also removed  
and replaced trailing slashes in my ProxyPass directives with no  
success.

Because I can’t seem to find any other documentation of this issue, I  
am left believing that this is a very trivial problem.

Please Help!

jeremy

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cavagnolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@Jeremy\_Cavagnolo](https://www.ruby-forum.com/u/Jeremy_Cavagnolo)\
**Post date:** [August 20, 2008, 7:56pm UTC](https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411/2 "2008-08-20T19:56:53Z")

</div>

This might help … I have the following rewrite rule in my conf  
file …

# Redirect all non-static requests to cluster

RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/(.\*)$ balancer://resman\_cluster%{REQUEST\_URI} [P,QSA,L]

Also, I have the following :

# Add a special request header so Rails redirects stay on https

RequestHeader set X\_FORWARDED\_PROTO “https”

HTH

Bill S.  
removed\_email\_address@domain.invalid  
AIM: siggelkowb  
Home: 770-457-8854  
Mobile: 770-354-2584

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cavagnolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@Jeremy\_Cavagnolo](https://www.ruby-forum.com/u/Jeremy_Cavagnolo)\
**Post date:** [August 20, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411/3 "2008-08-20T20:25:02Z")

</div>

Thanks for the reply.

It turns out that because I have the following permanent redirection,  
I don’t need to add the request header.

NameVirtualHost \*:80  
\<VirtualHost \*:80\>  
RedirectPermanent / [https://emiliano](https://emiliano) #this server is only accessed  
internally

However, my problem came from the fact that I left off the trailing  
slash from [https://emiliano](https://emiliano) in the RedirectPermanent directive.

Does anyone think it is still a good idea, from a performance  
standpoint, to include:

RequestHeader set X\_FORWARDED\_PROTO “https”

even though the requests are forwarded by the RedirectPermanent  
directive?

-jeremy

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cavagnolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@Jeremy\_Cavagnolo](https://www.ruby-forum.com/u/Jeremy_Cavagnolo)\
**Post date:** [August 20, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411/4 "2008-08-20T22:46:56Z")

</div>

Assuming you’re running a Rails app, and you want all things generated  
by link\_to, url\_for, etc. to keep you in HTTPS , then yes. Otherwise,  
you effectively double the number of HTTP requests that the browser  
makes. This is wasteful, and depending on your allocated bandwidth and  
popularity, costly.

Redirect them once to get them into HTTPS, but once they’re there, the  
X\_FORWARDED\_PROTO header is an exceedingly GOOD idea.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cavagnolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@Jeremy\_Cavagnolo](https://www.ruby-forum.com/u/Jeremy_Cavagnolo)\
**Post date:** [October 23, 2008, 10:47am UTC](https://www.ruby-forum.com/t/mod-proxy-mongrel-redirect-issue/146411/5 "2008-10-23T10:47:11Z")

</div>

Yes, but to use X\_FORWARDED\_PROTO header, this you must have two virtual  
blocks basically one for port=80 and other for port=443 so add this to  
443 block, and then the / problems will be solved.
