Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache VH - One port, 2 Boxes

Status
Not open for further replies.

wendi88

Technical User
Jan 30, 2007
4
US
I have exhausted figuring out something that should be very simple to do via httpd.conf configuration.

I have port 80 open on Box 1, but I need to either serve from that box or serve from Box 2, depending on the URL extension. I also need both boxes redirected to port 8080.

Box 1 (192.168.0.100): Redirects/serves via port 8080 on this first box when URL extension is /parents (e.g.
Box 2 (192.168.0.101): Redirects/serves via port 8080 on this second box when URL extension is /faculty (e.g.
I would think that this is a VERY basic configuration? Right now, the only works is the /parents URL extension. I’ve tried dozens and dozens of other configs to redirect to the second box (/faculty).

I'm hoping someone out there will save me! ...and the school :)

-Wendi
Linux (Fedora Core 5)

httpd.conf
==========
Listen 80
...
NameVirtualHost *:80

<VirtualHost 192.168.0.100:80>
ServerAdmin admin@preschool88.com
ServerName RewriteEngine On
RewriteRule ^/(.*) [L,P]
</VirtualHost>

<VirtualHost 192.168.0.101:80>
ServerAdmin admin@preschool88.com
ServerName RewriteEngine On
RewriteRule ^/(.*) [L,P]
</VirtualHost>

I'd be willing to open a port for each, if that would work. However, I cannot start Apache with a “double listen” (e.g. “Listen 80” [next line] “Listen 10080”) when I put this in the httpd.conf config file.
 
You've got a few issues here. It might help to know what you're trying to ultimately accomplish. First, it there a good reason that you're using 2 different machines? Second, why do you need to rewite to a different port number?

You have 2 virtualhosts listed that have the same name - you can't do that. I'm surprised that apache even works that way. I would guess that if it does start, it would be ignoring one of them (the first listed maybe?).

If 2 machines are actually reqired for some reason, I'd suggest that you set one machine as the 'front-end' web server. Then use it as a ReverseProxy to access the other 'back-end' web server (no port modifcation required on the back-end server)
 
Hi -- thanks for the feedback.

The reason I'm using two different boxes is to load balance the applications (they are weak servers). Also, I'd like each box to act as a back up/failover (not in scope right now).

What do you mean by each Virtual Host having the same name?

In any case, the following solution seems to work...

## Hosts file on Box 1 (192.168.0.100):

127.0.0.1 localhost.localdomain localhost
127.0.0.1 portal1.preschool88.com
127.0.0.1 portal2.preschool88.com

## httpd.conf:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName portal1.preschool88.com
RewriteEngine On
ReWriteRule ^/(.*) [L,P]
</VirtualHost>

<VirtualHost *:80>
ServerName portal2.preschool88.com
RewriteEngine On
ReWriteRule ^/(.*) [L,P]
</VirtualHost>

- Both boxes are running Apache
- Only Box1 has port 80 open for public access

Do you think there is a more effective/efficient way to do this?

Thanks!
-wendi
 
What you are trying to do does not provide 'load balancing' or 'fall over'. Apache itself isn't really intended to offer this function. For one thing, when doing this, there are DNS considerations, of which apache is entirely unaware.

Your original post had 2 VirtualHost containers. The ServerName directive in both had the same name. Was each of these VirtualHost containers from different httpd.conf files? The virual hosts from this most recent post, now have different ServerNames.

I think you're getting tangled up trying to do too many things at once on possible the same or different machines. Again, why do you need to rewrite to port 8080? If all access is from the same network, each apache web server can be running completely independant of the other, both on the standard port 80. The client [browser] access will be controlled by name resolution (or ip address). For the time being, until you get both web servers running the way you expect, I would elimate the URL rewriting issue. If you're trying to rewrite the port designation on 1 machine because of an issue with port forwarding through a router, that can be addressed as a secondary issue.

With 2 seperate apache web servers, each running only 1 host, there's really no need for VirtualHosts at all. They would each have their own independant httpd.conf something like:

Code:
# Parents web server
Listen 192.168.0.100:80
ServerName portal1.preschool88.com
DocumentRoot /var/[URL unfurl="true"]www/parents[/URL] [COLOR=green][i](or wherever is appropriate)[/i][/color]
Code:
# Faculty web server
Listen 192.168.0.101:80
ServerName portal1.preschool88.com
DocumentRoot /var/[URL unfurl="true"]www/faculty[/URL] [COLOR=green][i](or wherever is appropriate)[/i][/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top