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

谁说我不能喝 提交于 2019-12-12 01:46:01

问题


DESCRIPTION: We have two apache servers and one is behind haproxy. Our NEW server is behind the haproxy box, the OLD one is on a different network. I am going to create an apache rewrite rule to point this oldsite.com/some/thing to the new haproxy box (as seen below). This will redirect to newsite/some/other thing.

QUESTION: Is it possible to make this transparent to the user? I would like the user to only see oldsite.com/some/thing and not newsite/some/other/thing ? Is this achieveable with haproxy? I know a little about haproxy but not a lot. Thanks in advance for your time. much appreciated.


回答1:


Based on the tip from @Panama Jack, I created a basic test which I think will work for me. This is just the rough config and requires protections and so forth to get working fully. This is apache 2.4 (amazon AMI). As you see above, I am wanting to make the second server transparent to the user.

This example (quick and dirty) setup does the following:

  • login.HOST.info = login.DESTINATION.info
  • (user never sees the login.DESTINATION.info url that does the page actually exists on)

Server Handling Request:

<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/$1 [P,L]
</VirtualHost>

Final Server Handling the Request:

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



回答2:


See my first answer, but another way to do it is with one vhost and the use of the proxy:

ha proxy

 acl loc_req url_beg -i /uri/locator/location

(add lines to block to older server with !loc_req etc.)

vhost on new system

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


来源:https://stackoverflow.com/questions/39623199/redirect-to-new-domain-from-an-existing-domain-apache-haproxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!