Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I created a reverse proxy on the server where will proxy for "/users/sign_in" so that in url it would show And that worked fine in ubuntu and apache2. After enabling proxy in ubuntu, I set my virtual host like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/vhosts/
        <Directory /var/www/vhosts/>
                Options FollowSymLinks MultiViews
                AllowOverride All
        ProxyRequests Off
        <Proxy *>
          Order deny,allow
          Deny from all
          Allow from all
        ProxyPass /users/sign_in 
        ProxyPassReverse /users/sign_in
        ErrorLog /var/log/apache2/
        LogLevel warn
        CustomLog /var/log/apache2/ combined

Now here's the problem. /users/sign_in does a post request on the other server (the xyz server), that is, its an actual form that gets submitted, and the code on the other server redirects the user to the root of the website. Here's the log from the other server:

Started POST "/users/sign_in" for IPADDRESS at 2012-02-22 14:59:13 -0500
  Processing by Users::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "remote"=>"true", "commit"=>"Login", "user"=>{"email"=>"", "password"=>"[FILTERED]", "subdomain"=>"", "remember_me"=>"0"}}
Redirected to
Completed 302 Found in 110ms

So this is actually good it appears on the surface. The other server responded, signed the user in and then redirects them to the root url. The problem is they dont get redirected to the root url: (which contains the application code i want them to see). Rather they get redirected to which is the other server.

But if I add a proxy for in addition to in the server, then I will have a big problem. How will the browser know whent the user wants to see (the actual site content) and (the application that I want to load after the /users/sign_in is invoked).

I am completely stuck on this and open to any suggestions.

share|improve this question
Do you control – Zoredache Feb 23 '12 at 2:17
Is the intent to have the redirect send the user so they're pointing directly to after they've successfully signed in? Or do you want to keep their browser pointing to and serve them the content from the server? – Shane Madden Feb 23 '12 at 2:45
@ShaneMadden I want to keep their browser pointing to and serve them the content from the server. – JohnMerlino Feb 23 '12 at 6:08
@JohnMerlino Gotcha. So to be more specific: you want someone who's logged in on xyz successfully to be proxied to xyz for / (and all other content on the site? Or just /?) - while someone not logged in should get the content from the docroot local to the abc server? Did I get that right? And if so: what's the session cookie from the xyz server look like? – Shane Madden Feb 23 '12 at 6:11
@ShaneMadden you are exactly right. When someone is logged in on xyz, they should be proxied to xyz for all content of the site, while someone not logged in should get the content from the docroot local to the abc server. The session cookie from xyz looks like this (according to google chrome browser): Cookie: _session_id=d41c9ab959dc9198a0d6ef6bebbbacba – JohnMerlino Feb 23 '12 at 13:12
up vote 1 down vote accepted

Hmm - interesting deployment give this a shot. This will proxy all requests to the xyz server if the client sends a _session_id cookie.

RewriteEngine On
RewriteCond %{HTTP_COOKIE} _session_id=.+ [NC]
RewriteRule ^/(.*)$$1 [P,L]
ProxyPassReverse /

Put it below your existing ProxyPassReverse configuration; the order is significant for the ProxyPass directives.

This seems pretty fragile - I'm sure you have a reason for doing it like this, but is there no other way to separate the authenticated and unauthenticated sections of this application?

Edit: To have the xyz content served from /tracking instead:

ProxyPass /users/sign_in
ProxyPassReverse /users/sign_in
ProxyPass /tracking/
ProxyPassReverse /tracking/
share|improve this answer
thanks for respoonse, I think when you answered this question I responded with a comment above, saying that if its easier, i can redirect to – JohnMerlino Feb 23 '12 at 16:33
if i redirect to, would this change the code above? thanks for the responsers – JohnMerlino Feb 23 '12 at 16:33
So should deliver content from – Shane Madden Feb 23 '12 at 16:37
yes should deliver content from – JohnMerlino Feb 23 '12 at 16:40
i tried your initial solution and got this: The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /. Reason: DNS lookup failure for: (Note that i replaced with the real site address) – JohnMerlino Feb 23 '12 at 17:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.