在Apache2和Ubuntu的反向代理

因此,我在abc.com服务器上创build了一个反向代理,其中xyz.com/users/sign_in将代理“/ users / sign_in”,以便在url中显示abc.com/users/sign_in。 这在ubuntu和apache2中运行良好。 在ubuntu启用代理后,我设置我的虚拟主机是这样的:

<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> 

现在是这个问题。 / users / sign_in在其他服务器(xyz服务器)上发布了一个post请求,也就是它的一个实际提交的表单,另一个服务器上的代码将用户redirect到网站的根目录。 以下是来自其他服务器的日志:

 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"=>"[email protected]", "password"=>"[FILTERED]", "subdomain"=>"", "remember_me"=>"0"}} Redirected to http://abc.com/ Completed 302 Found in 110ms 

所以这实际上表面上看起来很好。 其他服务器响应,签署用户,然后redirect到根url。 问题是他们没有被redirect到根url:xyz.com(包含我希望他们看到的应用程序代码)。 相反,他们被redirect到另一台服务器abc.com。

但是,如果我在abc.com服务器上为xyz.com添加xyz.com/users/sign_in代理,那么我将遇到一个很大的问题。 浏览器如何知道用户想要查看abc.com(实际网站内容)和xyz.com(在/ users / sign_in被调用之后我想要加载的应用程序)。

我完全坚持这一点,并打开任何build议。

嗯 – 有趣的部署给了这一枪。 这将代理所有的请求到xyz服务器,如果客户端发送一个_session_id cookie。

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

把它放在你现有的ProxyPassReverseconfiguration下面。 订单对于ProxyPass指令是重要的。

这看起来很脆弱 – 我相信你有这样做的理由,但没有其他方式来分开这个应用程序的authentication和未authentication的部分?


编辑:要从/tracking代替xyz内容:

 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/