LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-13-2014, 08:03 AM   #1
Train
Member
 
Registered: Mar 2014
Distribution: Crunchbang
Posts: 44

Rep: Reputation: Disabled
Question 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.

Last edited by Train; 05-13-2014 at 08:05 AM.
 
Old 05-13-2014, 08:33 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,474

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
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.
 
Old 05-13-2014, 08:35 PM   #3
Train
Member
 
Registered: Mar 2014
Distribution: Crunchbang
Posts: 44

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
httpd multiple websites with physical and virtual hosting on apache with centos 6.4 jagdip Linux - Server 3 08-12-2013 07:22 PM
Multiple instances of apache on one physical server - Config lnx_2011 Linux - Newbie 1 04-03-2011 02:54 AM
Multiple SSL Virtual Hosts with Apache/mod_ssl/SNI ddenton Linux - Server 3 12-03-2008 02:20 AM
Apache 2 & Multiple Virtual Hosts hegele Linux - Networking 4 02-21-2004 06:41 PM
Having Problems With Apache 2 And Multiple Virtual Hosts hegele Linux - Software 0 02-18-2004 04:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration