April 18, 2024, 06:01:50 PM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Name bsed Virtual Host in apache + DNS  (Read 17987 times)

Offline Avin

  • Linux Learner
  • ***
  • Posts: 54
  • L!nuX
Name bsed Virtual Host in apache + DNS
« on: December 29, 2009, 12:08:38 PM »
Hello All,


 and   Wish you Verryyyyyyyyyy Happy New Year in Advance...

 
Now My query....  ???
I have configured Apache(2.0.52) and host three Rails site.
1) http://192.168.1.200:85   --   site1
2) http://192.168.1.200:90   --   site2
2) http://192.168.1.200:95   --   site3


    I am able to access those sites from internally from browser by IP and port (http://192.168.1.200:85) Now I configured Bind DNS  to create one domain (logical.com) for internal only to friendly accessing site. Now I am able to access site from name and dig it successfully for internal network.   Like

1) http://www.logical.com:85       for       http://192.168.1.200:85 
2) http://www.logical.com:90       for       http://192.168.1.200:90
2) http://www.logical.com:95       for       http://192.168.1.200:95 


But, I want
1) http://site1.logical.com           ---- should go    http://192.168.1.200:85 
2) http://site2.logical.com           ---- should go    http://192.168.1.200:90
2) http://site3.logical.com           ---- should go    http://192.168.1.200:95 


So, Where to configure that ??  APACHE or DNS  ??
 I don't want to specify port after site name. 
Any idea ???

Thanks,
Avin Tokade
« Last Edit: December 29, 2009, 12:13:29 PM by Avin »

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Re: Name bsed Virtual Host in apache + DNS
« Reply #1 on: December 30, 2009, 04:00:00 AM »
First of all, why you need to specify port for the the site.
I am not able to give you detailed answer but to help you out, you need to modify bind as well apache.

In apache you have to create virtual host,
It goes like :
Code: [Select]
Listen 80

# This is the IP of the server : 192.168.1.201, following will serve as default if IP address is entered directly
ServerName sub3.domain.com
DocumentRoot /www/mainserver

# This is the other address where you want to have more site to reside
NameVirtualHost http://192.168.1.200

<VirtualHost 192.168.1.200>
DocumentRoot /www/example1
ServerName sub2.example.com

# Other directives here ...

</VirtualHost>

<VirtualHost 192.168.1.200>
DocumentRoot /www/example2
ServerName sub1.example.org

# Other directives here ...
</VirtualHost>

In above we specified that sub1.example.org , sub2.example.org and sub3.example.org should be served from this apache, have specified document root for each domain.
Now we have to configure Bind to redirect request to this server and rest will apache do.

In Bind, you have to make A entries which points to Ip address 192.168.1.200 and 192.168.1.201 (which is main IP of server - if you want it).  You can edit template and create a zone file(zone file have information about a particular domain.
Add A entries like
sub1.example.org.    3600    IN     A      192.168.1.200
sub2.example.org.    3600    IN     A      192.168.1.200
sub3.example.org.    3600    IN     A      192.168.1.201


This way, bind will resolve all request for those domains to this IP and done. However, remember, here I just gave basic info, you need to little read about to make it happening.
Hope it helps.



Offline Avin

  • Linux Learner
  • ***
  • Posts: 54
  • L!nuX
Re: Name bsed Virtual Host in apache + DNS
« Reply #2 on: December 30, 2009, 06:18:22 AM »
Thanks Ricky for Quick Reply, :)

I have one doubt.  Is it possible to NAT this site to outside (Internet) access ?
 Right now I am accessing those site from My Live IP  and specific port (http://122.160.x.x:90). My Apache server is also work as Proxy(Squid) and Gateway for our network, So I NAT those sites using firewall (IPTABLE). Like  (From Internet) http://122.160.x.x:90  to  http://192.168.1.200:90.
If I configure as you say. Is it possible to fulfill my requirement ??
I only want name base site(without port specified)for Internally.   I haven't ragister our domain yet. So It is ok, to access our site from our Live IP and Port which I specified.

Sorry for My Bad English.... 

Avin Tokade 
     

Offline Ricky

  • LST CareTaker
  • Specially Skilled
  • *****
  • Posts: 2381
Re: Name bsed Virtual Host in apache + DNS
« Reply #3 on: December 31, 2009, 06:40:40 PM »
You are already able access them through internet or you want to access them through internet ?

Offline Avin

  • Linux Learner
  • ***
  • Posts: 54
  • L!nuX
Re: Name bsed Virtual Host in apache + DNS
« Reply #4 on: January 01, 2010, 06:00:02 AM »
First of all " Wish You Very Happy and Prosperous New Year "

yes, I already access sites from outside but from Live IP with port no. Right now I have configured Apache as IP base and I also setup all site with specific port. So I am easily able to NAT the site in Firewall (IPTABLES) to access from outside.
Like,
http://122.160.x.x:90  to  http://192.168.1.200:90.

My old Virtual Host session.
<VirtualHost 192.168.1.200:90>
 DocumentRoot /var/www/html/site1
 ServerName site1.logical.com
 ErrorLog logs/site1.log
 CustomLog logs/site.log common
</VirtualHost>
 

So, My query is if I configure Name base Virtual host as you suggested then how to NAT those site in IPTABLES, because I haven't registered my domain yet. and no port number in Virtual host for site.

I only want If any internal user want to try to access site site1.logical.com then It will go to http://192.168.1.200:90. Right now all user accessing site but url with port no. (http://site1.logical.com:90).

And one more little query.. You showing two IP in Apache  192.168.1.201 as Server IP. and 192.168.1.200 for virtual host.

I have only one Local IP on Server. Which you call say All rounder which act as PROXY, FIREWALL, DHCP,  DNS, WEB SERVER, FTP SERVER and FILE SERVER for our network. 

So Is it possible to do  Apache Server and Virtual Host in one local IP ?


Avin Tokade..
« Last Edit: January 01, 2010, 06:07:35 AM by Avin »

Offline kaushalpatel1982

  • LST CareTaker
  • Linux Learner
  • *****
  • Posts: 87
Re: Name bsed Virtual Host in apache + DNS
« Reply #5 on: January 01, 2010, 09:17:28 AM »
HTTP protocol is always works on port 80. When ever you change the port of the service you have to specify the same thing to client when they are accessing it.   

When you are configuring the Virtual Host, you need not to provide port. Use as it is. It should work properly.
« Last Edit: January 01, 2010, 09:19:20 AM by kaushalpatel1982 »