Hosts file question and maybe Apache?

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Hosts file question and maybe Apache?

Post by alex.barylski »

I have a dedicated host and I have a single domain and dedicated IP.

I requested my hosting provider add my domain to their zone file so I could use their DNS. Apparently I have to notify them each time I wish to add or remove a domain.

Currently my hosts file looks like this:

Code: Select all

 
cl-t022-201cl:/etc# cat hosts
127.0.0.1       localhost
127.0.1.1       deb.[b]mydomain[/b].com      deb
 
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
xx.xx.xxx.xxx           cl-t022-201cl.[b]mydomain[/b].com    cl-t022-201cl
 
QUESTION: Shouldn't the last line reflect my actual domain, mapping the IP address to my sole mycompany.com domain??? What are these lines doing exactly?

If I wanted to add multiple subdomains to a single IP address but each subdomain pointed to a different subdirectory, how is this done?

Basically I have one domain name (mycompany.com) and I have a single dedicated IP but I wish to have many subdomains each of which should point to a subdirectory.

Can someone show me what this might look like?

Cheers :)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Hosts file question and maybe Apache?

Post by alex.barylski »

I just quickly read up my Apache phrasebook and I think I've better understood what my confusion is all about.

I think I was failing to see that Apache is only one part of the entire solution. DNS and my local hosts file also play a role in delivering my pages to users via subdomains.

Virtual hosting simply maps the subdomain to the actual directory but the hosts file is what is used to route subdomains (which is where I'm confused) and my hosting companies DNS is what maps the domain to my IP address and the registrar (GoDaddy) is responsible for looking up the TLD???

Subdomains are accessible even without Apache installed?

So what still confuses me, is in my local hosts file, if I add subdomains, how do I map them to a single IP address? Do I have to use port numbers? Can I map them to subdirectories?

If I map each one to the same IP address will this still work? Why does it work?

Cheers :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Hosts file question and maybe Apache?

Post by VladSun »

:) You really hate the DNS stuff ;)

1. The DNS has nothing to do with Apache or whatever www server. ;)
Why? Because Apache reads the domain/subdomain you want to view from the headers like GET, POST, etc. That's what Apache does when configured for name-based virtual hosts.
Yes, you need to have an A record in a public reachable DNS server for each virtual host in Apache in order to make "normal" HTTP requests to your www server.
2. Local /etc/hosts file has nothing to do with Apache and worldwide DNS :)
If you don't have a domain name served by reachable DNS, you can edit /etc/hosts file on the *client* machine in order to make "normal" HTTP requests to your www server.
3. Multiple sub/domains are binded to a single IP by using CNAME records ... (I know we've talked about it ;) )
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Hosts file question and maybe Apache?

Post by alex.barylski »

I do hate DNS yes...I'm not really interested in learning it...I want to just focus on development and LAMP but it's a nessecary evil -- so I'm forcing myself to learn it as opposed to just hiring someone to set it all up for me. :banghead:

I have read DNS articles and even entire sections of some books I own on the subject...for some reason the logic just evades me. :P

Given my situation then, will I be able to setup subdomains using my local hosts file? Or do I need to inform my hosting company each time a client signs up?

The alternative so I have been told, is to setup my own DNS. Wouldn't this require two nameservers though? I only have a single dedicated server and I'm not really interested in setting up and learning Bind.

If the domain (mycompany.com) is added to my hosting companies DNS zone file, anybody that enters that domain is indeed directed to my web site (confirmed). Should my local hosts not be capable of using the domain and directing to subdomains appropriately -- as my server is now in control is it not?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Hosts file question and maybe Apache?

Post by VladSun »

Forget about using your server /etc/hosts file for such things.

If you answer some questions I'll be able to help...
As far as I understand you this is the situation:
1. You have a dedicated Linux machine with Internet access and public IP.
2. You want to have a www server on this machine which has to be configured for name-based virtual hosts.
3. You have a domain and want to use subdomains of this domains for your clients.

So ... who does manage/serve your mycompany.com domain name zone?
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Hosts file question and maybe Apache?

Post by alex.barylski »

1) Yes
2) Yes
3) Yes

A dedicated hosting company iWeb.ca

I think I understand now that local hosts file won't do the trick.

When someone enters a URL into their address bar: sub.domain.com

1) Browser looks up TLD (.com) via one of 12 authoratative DNS servers
2) One of the 12 DNS servers respond and forward request onto GoDaddy (my registar)
3) GoDaddy looks up mycompany.com and returns the nameservers I assigned to my domain
4) Two nameservers are provided by hosting company (iWeb) these provide rDNS and DNS.

I thought at this point my server was in complete control, but it sounds as though it's still DNS or my server companies DNS servers.

So I would need to setup a DNS and reverse DNS locally on my machine? What confuses me though is how this would happen. Does it mean I have to setup two name servers and assign my GoDaddy account details to point to these custom nameservers?

http://faq.iweb.ca/en/article.php?id=090

I basically need (ideally not nessecary) the ability to programatically add subdomains as each client account would be accessed this way:

somecompany.mycompany.com
abcmarketing.mycompany.com

The alternative to the above of course is to use subdirectories but that looks nasty and I would prefer subdomains.

My hosting says I just need to contact them and ask to have the subdomains added but I would prefer to have direct control over this so I can programatically add the appropriate records to zone files, etc whenever someone signs up.

Possible? Do I need my own nameservers? I would really prefer to avoid setting up DNS, etc. Maybe I should just use subdirectories.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Hosts file question and maybe Apache?

Post by alex.barylski »

EDIT | Just realizes this is likely not possible cause the subdirectories are delivered by Apache not DNS -- it would have to be subdomain to subdomain, correct? Shoot. :banghead: :lol:

You know what would work also (actually be even better).

If each client already had a domain name they used on a shared host somewhere...if one of their own subdomains could be mapped that would be even more superior.

so something like:

http://www.mycompany.com/someclient/ => myprog.someclient.com

So they could access my software apparently through their own subdomain...that would be stellar. What would they need to do on their own end to accomplish this? Or would I have to ask my hosting provider to essentially make that mapping for me?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Hosts file question and maybe Apache?

Post by VladSun »

Most ideally it would be if you setup your own DNS server (master) and make your hosting DNS server slaves :)
Then every time you make modifications on you zone files the slaves servers will be notified and they will renew their zone files with the ones your master DNS has transferred.

And yes - you can use clients' subdomains pointing to your IP address. Maybe this would be the easiest way for you :)
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Hosts file question and maybe Apache?

Post by alex.barylski »

And yes - you can use clients' subdomains pointing to your IP address. Maybe this would be the easiest way for you
Absolutely...prefered as well. But I'm not sure I know what I would have to request of my clients inorder to accomplish such a thing?

Do they need to setup a subdomain with their registrar (GoDaddy) and have the subdomain point to my hosting companies name servers?

What steps would I need to carry out for each client?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Hosts file question and maybe Apache?

Post by VladSun »

Hockey wrote:EDIT | Just realizes this is likely not possible cause the subdirectories are delivered by Apache not DNS -- it would have to be subdomain to subdomain, correct? Shoot. :banghead: :lol:
OK, you ask your client to put an A record in *his* domain zone file like this:

Code: Select all

 
hockey.clientdomain.com.       IN      A     your.server.ip.here
 
then setup a virtual host section in you httpd.conf file:

Code: Select all

<VirtualHost *:80>
    DocumentRoot "/htdocs/somename"
    ServerName hockey.clientdomain.com
    ErrorLog "logs/hockey-error.log"
    CustomLog "logs/hockey-access.log" common
</VirtualHost>
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Hosts file question and maybe Apache?

Post by alex.barylski »

Sweet. Thanks, I'll certainly try that. :)
Post Reply