LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache rewrite_module to multiple virtual hosts on a separate physical server. (https://www.linuxquestions.org/questions/linux-server-73/apache-rewrite_module-to-multiple-virtual-hosts-on-a-separate-physical-server-4175504821/)

Train 05-13-2014 08:03 AM

Apache rewrite_module to multiple virtual hosts on a separate physical server.
 
I have a router with port 80 forwarded to physical server "A".

On physical server "A" I have Raspbian and Apache2. Apache2 is configured for name-based virtual hosting with rewrite_module to rewrite requests for "Domain1" to physical server "B".

Physical server "B" has Crunchbang and Apache2. Apache2 is configured for name-based virtual hosting for "Domain1" and "Domain2".

"Domain1" works and "Domain2" does not work when accessing outside the lan (request through physical server "A"). It does work for both domains on the lan (with requests not going through physical server "A").

Is there a way to have mod_rewrite work for 2 name-based virtual hosts on the same physical server with 1 IP address?

(It works on more than one physical server hosting 1 name-based virtual host, but not 1 physical server hosting several virtual hosts)

Below are the configuration files on physical server "A" running Raspbian and Apache2:

/etc/apache2/apache2.conf
Code:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

ServerName respberrypi

/etc/apache2/sites-availible/domain1
Code:

<VirtualHost *:80>
    ServerName domain1.org
    ServerAlias domain1.org
    RewriteEngine    On
    RewriteRule      ^(.*)$      http://domain1.org$1  [P]
</VirtualHost>

/etc/apache2/sites-availible/domain2
Code:

<VirtualHost *:80>
    ServerName domain2.org
    ServerAlias domain2.org
    RewriteEngine    On
    RewriteRule      ^(.*)$      http://domain2.org$1  [P]
</VirtualHost>

My /etc/hosts file has the domains pointing to the correct IP addresses.

TenTenths 05-13-2014 08:33 AM

A quick look at your set up would indicate that if you are on the LAN the machines are going direct to server2 for domain2 and not going through the server1 VHost. External requests are being told to rewrite from domain2.org/ to.... domain2.org/ which will loop as I'm guessing you have domain2.org pointed to your public IP.

For this kind of thing people have used apache as a reverse proxy or you could look at using haproxy instead of apache and configure hdr_dom(host) rules to direct traffic to server1 or server2 accordingly.

Train 05-13-2014 08:35 PM

Quote:

Originally Posted by TenTenths (Post 5169926)
A quick look at your set up would indicate that if you are on the LAN the machines are going direct to server2 for domain2 and not going through the server1 VHost. External requests are being told to rewrite from domain2.org/ to.... domain2.org/ which will loop as I'm guessing you have domain2.org pointed to your public IP.

For this kind of thing people have used apache as a reverse proxy or you could look at using haproxy instead of apache and configure hdr_dom(host) rules to direct traffic to server1 or server2 accordingly.

haproxy looks good, I can try that.

Yes, on the LAN they are going direct to the physical server and not through the Pi.
I did have them specified by IP addresses at first with the same result. Either way, the hosts file on "Server A (Raspberry PI)" points to the correct IP's on the LAN for the domains.

All the domain names are at Active-Domains. They all point to one IP address which is my public static IP address which goes to my router which ALL the http requests are forwarded only to the "Server A (Raspberry PI)" which runs Apache and has the rewrite modules.


All times are GMT -5. The time now is 06:15 AM.