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