问题
These two machines A and B are NAT behind 1 IP address.
Url.xyz.com goes to machine A on port 80 served by apache 2.2 and url2.xyz.com is supposed to go to machine B on port 80 served by apache 2.2 on that machine
i have machine A taking all inbound port 80 packets from my gateway...fyi
at one point i had apache on machine A setup to do this, but now i am struggling to regain the good config. I am using a diff OS on a diff Machine B for good reasons....
i recall setting up virtual server url2.xyz.com in apache 2.2 on machine A using port 80, then setting the host file on machine A and B to have a line titled:
192.168.0.x url2.xyz.com url2
and setting the document root for url2.xyz.com in apache on machine A equal to the document root on machine B. (it won't take a blank field....)
I am either dreaming, or missing a slight setup step. Any help appreciated. As I recall, from about six months ago, it seemed that apache on machine A read the host file and did this right..
the net good result is (hopefully) that the virtual server on machine A gets content from machine B (or C, or D, etc...)
alternatively i will try to get another Ip address from my provider.
回答1:
One possibility is to have machine A act as a proxy for machine B. Meaning all requests for both domains go to machine A on port 80, but then you set up name based virtual hosts in apache. The virtual host for url2.xyz.com then forwards on the request to machine B.
Something like this:
Virtual hosts on machine A:
<VirtualHost *:80>
ServerName url1.xyz.com
DocumentRoot /var/www/url1
</VirtualHost>
<VirtualHost *:80>
ServerName url2.xyz.com
ProxyPass / http://url2.machineB/
ProxyPassReverse / http://url2.machineB/
</VirtualHost>
And then on machine A you define url2.machineB to point to the IP address of machine B. You do this by adding a line to the file /etc/hosts. Then on machine B you create an apache virtual host to listen for that domain, like so:
<ViirtualHost *:80>
ServerName url2.machineB
DocumentRoot /var/www/url2
</VirtualHost>
This might not be exactly the solution, but should give you one option to take. See http://httpd.apache.org/docs/2.2/mod/mod_proxy.html for more on proxying.
来源:https://stackoverflow.com/questions/8318969/how-to-redirect-two-urls-on-same-port-to-two-diff-ips-internally