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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual Host configuration

Status
Not open for further replies.

apachevhnewbie

Technical User
Mar 9, 2010
3
US
I've a domain and also created a CNAME subdomain sub.mydomain.com for my only external ip address *.*.*.*

In my current environment, I've have an Apache web server (10.1.10.1) port 80 and 443 opened, a web application server 1 (10.1.10.2) and web application server 2 (10.1.10.3).

So, what I am trying to do is that I want to configure using virtual host on my apache web server (10.1.10.1) so that when I connect to from IE, It will redirect me to web application server 1 (10.1.10.2) home page and when I do sub.mydomain.com from IE, It will redirect me to web application server 2 (10.1.10.2)

The other thing that I'm troubling with is the DocumentRoot paremeter in the virutal host config file. Since I'm trying to redirect to my internal ip addresses meaning that my web applications are reside on 10.1.10.2 and 10.1.10.3 respectively. They are not on the apache web server. Therefore what is the parameter for DocumentRoot? Thanks in advance
 
apachevhnewbie, first off welcome to the forums.

I had to read your post a couple of times, but I think I understand what you are trying to achieve. To paraphrase: you want to have mydomain.com serve up one page and sub.myodmain.com to go to a different one. Currently you have setup different server IP addresses for these servers. You are also using private LAN IP addresses (10.x.x.x).

There are a couple of ways you can achieve your goal and it sounds like you may be currently mixing them. Your first option would be to use virtual hosts. A virtual host allows you to have multiple domains on the same IP address where apache will serve up the page based upon the requested domain. The key here is that the different domains share the same IP address.

The other option would be to put them on different servers or to use multiple NIC cards (or perhaps alias IPs) on the same server. Then you could either run multiple copies of apache or have the hosts listen to their respective IP address. In your setup, this gets complicated because you would need a means to forward or proxy to the perspective server by way of IP address. If you have multiple PUBLIC IP addresses you can simply forward based on IP address. Otherwise, you will need to run a proxy, such as apache's mod_proxy, to forward the request to the server designated.

This part of the setup is different than document root. Document root specifies the location of the web page files (HTML, PHP, etc). For example, in my setup, these are located at /var/ one of my virtual hosts and /var/www2 for the other. This way apache knows where to get the files associated with either host when it is requested by domain name.

Hopefully that helps clarify things for you. If not, just respond and we will try to help you as best we can.
 
Hi Noway2, First of, I greatly appreciated your prompt response. Secondly, I apologized for not being clear.

What I'm trying to accomplish is that I want to use and sub.mydomain.com for my only public IP address x.x.x.x.

My current environment consits of an apache web server assigned to a private LAN IP address(10.x.x.1), a web application server 1 (10.x.x.2) and a web application server 3 (10.x.x.2). When I'm within the private LAN, I browse to 10.x.x.2 and 10.x.x.3 respectively to get to these web applications. I'm having trouble with figuring out what exactly will be the parameters for my httpd-vhost.conf:

Below is what I currently have in the httpd-vhost file.

------------
Listen 80
Listen 8080

NameVirtualHost 10.x.x.2:80
NameVirtualHost 10.x.x.2:8080
NameVirtualHost 10.x.x.3:80
NameVirtualHOst 10.x.x.3:8080

<VirtualHost 10.x.x.2:80>
ServerName DocumentRoot / <--what's going to be for my configuration-->
</VirtualHost>

<VirtualHost 10.x.x.2:8080>
ServerName DocumentRoot /</VirtualHost>

<VirtualHost 10.x.x.3:80>
ServerName sub.mydomain.com
DocumentRoot /</VirtualHost>

<VirtualHost 10.x.x.3:8080>
ServerName sub.mydomain.com
DocumentRoot /</VirtualHost>
 
Hi Noway2, First of, I greatly appreciated your prompt response. Secondly, I apologized for not being clear.

What I'm trying to accomplish is that I want to use www.mydomain.com and sub.mydomain.com for my only public IP address x.x.x.x. In other words, my public DNSes current resolved to my public ip address.

My current environment consits of an apache web server assigned to a private LAN IP address(10.x.x.1), a web application server 1 (10.x.x.2) and a web application server 3 (10.x.x.2). SO, when I'm within the private LAN, I browse to 10.x.x.2 and 10.x.x.3 respectively to get to these web applications.

I'm having trouble with figuring out what exactly will be the parameters for my httpd-vhost.conf

Below is what I currently have in the httpd-vhost file.

------------
Listen 80
Listen 8080

NameVirtualHost 10.x.x.2:80
NameVirtualHost 10.x.x.2:8080
NameVirtualHost 10.x.x.3:80
NameVirtualHOst 10.x.x.3:8080

<VirtualHost 10.x.x.2:80>
ServerName DocumentRoot / <--what's going to be for my configuration?-->
</VirtualHost>

<VirtualHost 10.x.x.2:8080>
ServerName DocumentRoot /</VirtualHost>

<VirtualHost 10.x.x.3:80>
ServerName sub.mydomain.com
DocumentRoot / <--what's going to be for my configuration?-->
</VirtualHost>

<VirtualHost 10.x.x.3:8080>
ServerName sub.mydomain.com
DocumentRoot /</VirtualHost>
 

I assume you are doing some port forwarding with the single external IP? There is no way to distinguish the port 80 traffic (unless it does some deep packet inspection). You probably can only port forward the 80 traffic inbound to a single 10
address...there is no way to forward to both 10.x.x.2 and 10.x.x.3 with a single external IP.

So externally, I don't think it can work with a single IP without specifying ports or adding external ips.

Could be wrong, however.
 
OK, I'm really good at sticking my foot in my mouth most of the time, but I don't understand this at all... I have a very logical way of thinking that sometimes gets me in trouble, but...

If you want to go to server1 and sub.mydomain.com to go to server2, and since these all have different IP addresses (unless your one box has 3 network cards in it) I assume they are all different boxes, then why would you be trying to do this with a 3rd instance of Apache??

I would use DNS for the domain to direct traffic. DNS would be a lot less burdened than an Apache server trying to direct all that traffic and it would be a LOT more search engine friendly than all those redirects.

All you would need to do is setup the domain for "mydomain.com" and say "www" goes to 10.1.10.2 and "sub" goes to 10.1.10.3. Both of those boxes would be running their own versions of apache and would serve up whatever is requested of them. That also provides some redundancy in your network so that if one of the servers ever takes a dump you can quick restore your content to the other one while you are rebuilding and a quick tweak to DNS and your all set to go in a flash.

Your DNS server (likely bind) would be running on your own network and would be exposed to your outside IP address. All you have to do is route port 53 through to whatever box is running your DNS, and the DNS will route the request to whichever server it needs to go to.

This is all subject to someone disagreeing, but I do something pretty similar on my Comcast box excepting for the fact that I have multiple static IP addresses that are all visible to the outside. Getting a block of static IP addresses is pretty cheap if it makes the solution any easier....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top