Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I created a reverse proxy on the abc.com server where xyz.com/users/sign_in will proxy for "/users/sign_in" so that in url it would show abc.com/users/sign_in. 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
        ServerName abc.com
        ServerAlias www.abc.com
        DocumentRoot /var/www/vhosts/abc.com/public_html
        <Directory /var/www/vhosts/abc.com/public_html/>
                Options FollowSymLinks MultiViews
                AllowOverride All
        </Directory>
        ProxyRequests Off
        <Proxy *>
          Order deny,allow
          Deny from all
          Allow from all
        </Proxy>
        ProxyPass /users/sign_in http://xyz.com/users/sign_in 
        ProxyPassReverse /users/sign_in http://xyz.com/users/sign_in
        ErrorLog /var/log/apache2/abc.com-error.log
        LogLevel warn
        CustomLog /var/log/apache2/abc.com-access.log combined
</VirtualHost>

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"=>"xyz@xyz.net", "password"=>"[FILTERED]", "subdomain"=>"", "remember_me"=>"0"}}
Redirected to http://abc.com/
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: xyz.com (which contains the application code i want them to see). Rather they get redirected to abc.com which is the other server.

But if I add a proxy for xyz.com in addition to xyz.com/users/sign_in in the abc.com server, then I will have a big problem. How will the browser know whent the user wants to see abc.com (the actual site content) and xyz.com (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 abc.com? –  Zoredache Feb 23 '12 at 2:17
    
Is the intent to have the redirect send the user so they're pointing directly to xyz.com after they've successfully signed in? Or do you want to keep their browser pointing to abc.com and serve them the content from the xyz.com server? –  Shane Madden Feb 23 '12 at 2:45
    
@ShaneMadden I want to keep their browser pointing to abc.com and serve them the content from the xyz.com 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

1 Answer 1

up vote 0 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 ^/(.*)$ http://xyz.com/$1 [P,L]
ProxyPassReverse / http://xyz.com/

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 http://xyz.com/users/sign_in
ProxyPassReverse /users/sign_in http://xyz.com/users/sign_in
ProxyPass /tracking/ http://xyz.com/
ProxyPassReverse /tracking/ http://xyz.com/
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 abc.com/tracking –  JohnMerlino Feb 23 '12 at 16:33
    
if i redirect to abc.com/tracking, would this change the code above? thanks for the responsers –  JohnMerlino Feb 23 '12 at 16:33
    
So abc.com/tracking/ should deliver content from xyz.com/? –  Shane Madden Feb 23 '12 at 16:37
    
yes abc.com/tracking/ should deliver content from xyz.com/ –  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: xyz.com (Note that i replaced xyz.com with the real site address) –  JohnMerlino Feb 23 '12 at 17:03

Your Answer

 
discard

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.