从现有域重定向到新域 (Apache / haproxy)

Redirect to new domain from an existing domain (Apache / haproxy)

描述: 我们有两台 apache 服务器,其中一台在 haproxy 后面。我们的新服务器在 haproxy box 后面,旧服务器在不同的网络上。我将创建一个 apache 重写规则以将此旧站点指向新的 haproxy 框(如下所示)。com/some/thing。这将重定向到 newsite/some/other 东西。

问题: 是否可以让这对用户透明?我希望用户只看到 oldsite.com/some/thing 而不是 newsite/some/other/thing ?这可以用 haproxy 实现吗?我对 haproxy 了解一点,但不是很多。在此先感谢您的时间。非常感谢。

根据@Panama Jack 的提示,我创建了一个我认为对我有用的基本测试。这只是粗略的配置,需要保护等才能充分发挥作用。这是 apache 2.4(亚马逊 AMI)。正如您在上面看到的,我想让第二个服务器对用户透明。

此示例(快速而肮脏)设置执行以下操作:

  • login.HOST.info = login.DESTINATION.info
  • (用户永远不会看到页面实际存在的 login.DESTINATION.info url)

服务器处理请求:

<VirtualHost *:80>
    ServerAdmin admin@localhost
    ServerName login.HOST.info
    ServerAlias www.login.HOST.info
    ErrorLog logs/login-error_log
    CustomLog logs/login-access_log common
    RewriteEngine On
    RequestHeader add X-SSL off
    RewriteRule ^/(.*) http://login.DESTINATION.info/ [P,L]
</VirtualHost>

处理请求的最终服务器:

<VirtualHost *:80>
    ServerName login.DESTINATION.info
    ServerAdmin webmaster@site.com
    DocumentRoot /var/www/deal/site/locator/whatever/

    RemoteIPHeader X-Forwarder-For    # allows the host to remain
    RemoteIPInternalProxy XXXX.0.0.0/8   # ip of other machine
</VirtualHost>

请参阅我的第一个答案,但另一种方法是使用一个虚拟主机并使用代理:

ha 代理

 acl loc_req url_beg -i /uri/locator/location

(使用 !loc_req 等添加要阻止旧服务器的行)

新系统上的虚拟主机

<VirtualHost *:80>
   ServerAdmin admin@localhost
   ServerName login.HOST.info 
   ... ....
   Alias /uri/locator/location /www/actual/path/to/new/location
   ... .....