Setting up a sub-domain on a Linux box
Moderator: General Moderators
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
Setting up a sub-domain on a Linux box
Does this require the use of a DNS server on the box you're hosting a sub-domain? I understand the part of creating a new A record on the DNS record but what actions do I need to take on the server that's hosting the sub-domain?
Regards,
Regards,
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Simply edit your /etc/hosts file..
(I'm pretty sure i've posted a couple of examples in the apache-webserver forum at phpdn).
If you want to make sure other people can access the new domains too, yes, you'll have to add an A or CNAME record to your dns configuration so that blah.example.com points to the ip (or hostname) where the webserver is running....
And then add virtualhosts to your apche configuration...127.0.0.1 localhost.localdomain localhost CWBE-VM005 mysite.localhost
(I'm pretty sure i've posted a couple of examples in the apache-webserver forum at phpdn).
If you want to make sure other people can access the new domains too, yes, you'll have to add an A or CNAME record to your dns configuration so that blah.example.com points to the ip (or hostname) where the webserver is running....
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
(Not referring to local domains via /etc/hosts here)
You just need to create new A records at the DNS end of things. The have those subdomains bring up different web content over HTTP you need to create NameBasedVirtualHost's in Apache or the equivalent in your web server. Basically the sub-domain will point to the same IP so is effectively the same as far as TCP/IP goes, but HTTP send the name of the domain along with the request, so Apache can see the domain name that was requested and deliver content accordingly
EDIT | Sorry tim, I didn't read your post fully
You just need to create new A records at the DNS end of things. The have those subdomains bring up different web content over HTTP you need to create NameBasedVirtualHost's in Apache or the equivalent in your web server. Basically the sub-domain will point to the same IP so is effectively the same as far as TCP/IP goes, but HTTP send the name of the domain along with the request, so Apache can see the domain name that was requested and deliver content accordingly
EDIT | Sorry tim, I didn't read your post fully
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I don't need anyone from the outside accessing it (yet anyways) but here is my current hosts file:timvw wrote:Simply edit your /etc/hosts file..127.0.0.1 localhost.localdomain localhost CWBE-VM005 mysite.localhost
what would I add to this file if I wanted to add a subdomain forums.localhost or forums.pcspectra-dev???127.0.0.1 localhost
127.0.1.1 pcspectra-dev
# 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
Then I have to add an entry for apache which I assume is what maps the directory to the subdomain name?
You wouldn't care to show me explicity what I would need to edit inorder to add a sub-domain (forums) would you?
Cheers
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Either:
Or
Either will point the sub-domain to 127.0.0.1 if resolved locally. You then just need to modify httpd.conf if you plan on using these sub-domains for different websites.
Code: Select all
127.0.0.1 localhost forums.localhost
127.0.1.1 pcspectra-dev
# 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-allhostsCode: Select all
127.0.0.1 localhost
127.0.1.1 pcspectra-dev
127.0.0.1 forums.localhost
# 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-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Bam...perfect...I got everything working how I expected...
Couple more questions...
I get the Apache config directives and how they work...sorta...but the HOSTS file...is that part of Apache or part of the default linux install...is it's purpose basically to act as a local DNS???
So I could in theory I could bind my local loopback address: 127.0.0.1 to a domain like pooptest.com and whenever I entered http://pooptest.com it would act as localhost???
If you could just yes or no me on that one...it would certainly clear everything up a little...or better yet explain it...as the more I read about how it all works from the more sources I find the better off I am
Secondly...if I needed to programatically locate that HOSTS file...is there a way?
Also, one more thing...
Under localhost I have a directory setup like:
docroot/myprojects
docroot/tempprojects
docroot/payprojects
I typically work under the /myprojects directory which is further broken up:
cms/
crm/
kbase/
and so on...
Right now, the project I'm working with is accessed via HTTP as: http://localhost/myprojects/someapp and I have mapped a forums subdomain to localhost so despite being for the above someapp it's actually accessed as: http://forums.localhost
It works, but looks awkward...
So I would obviously have to change my docroot to instead of /htdocs it would be /htdocs/myprojects/someapp the problem is...whenever I need to work on someapp_version3.4 I would need to again change the docroot...
So I wonder...is it possible to specify a docroot using .htaccess??? That way depending on which directory I start, Apache assume the local docroot instead of the default....and I think I just answered my own question there...as I can't see that being technically possible...
bummer
Couple more questions...
I get the Apache config directives and how they work...sorta...but the HOSTS file...is that part of Apache or part of the default linux install...is it's purpose basically to act as a local DNS???
So I could in theory I could bind my local loopback address: 127.0.0.1 to a domain like pooptest.com and whenever I entered http://pooptest.com it would act as localhost???
If you could just yes or no me on that one...it would certainly clear everything up a little...or better yet explain it...as the more I read about how it all works from the more sources I find the better off I am
Secondly...if I needed to programatically locate that HOSTS file...is there a way?
Also, one more thing...
Under localhost I have a directory setup like:
docroot/myprojects
docroot/tempprojects
docroot/payprojects
I typically work under the /myprojects directory which is further broken up:
cms/
crm/
kbase/
and so on...
Right now, the project I'm working with is accessed via HTTP as: http://localhost/myprojects/someapp and I have mapped a forums subdomain to localhost so despite being for the above someapp it's actually accessed as: http://forums.localhost
It works, but looks awkward...
So I would obviously have to change my docroot to instead of /htdocs it would be /htdocs/myprojects/someapp the problem is...whenever I need to work on someapp_version3.4 I would need to again change the docroot...
So I wonder...is it possible to specify a docroot using .htaccess??? That way depending on which directory I start, Apache assume the local docroot instead of the default....and I think I just answered my own question there...as I can't see that being technically possible...
bummer
-
nickvd
- DevNet Resident
- Posts: 1027
- Joined: Thu Mar 10, 2005 5:27 pm
- Location: Southern Ontario
- Contact:
Pretty Much, yup!Hockey wrote:Bam...perfect...I got everything working how I expected...
Couple more questions...
I get the Apache config directives and how they work...sorta...but the HOSTS file...is that part of Apache or part of the default linux install...is it's purpose basically to act as a local DNS???
Yep... (not really 'acting' like localhost, it will just resolve to the loopback, just as 'localhost' does)Hockey wrote: So I could in theory I could bind my local loopback address: 127.0.0.1 to a domain like pooptest.com and whenever I entered http://pooptest.com it would act as localhost???
Should be as simple (and as universal) as /etc/hosts...Hockey wrote: If you could just yes or no me on that one...it would certainly clear everything up a little...or better yet explain it...as the more I read about how it all works from the more sources I find the better off I am
Secondly...if I needed to programatically locate that HOSTS file...is there a way?
Um?Hockey wrote: Also, one more thing...
Under localhost I have a directory setup like:
docroot/myprojects
docroot/tempprojects
docroot/payprojects
I typically work under the /myprojects directory which is further broken up:
cms/
crm/
kbase/
and so on...
Right now, the project I'm working with is accessed via HTTP as: http://localhost/myprojects/someapp and I have mapped a forums subdomain to localhost so despite being for the above someapp it's actually accessed as: http://forums.localhost
It works, but looks awkward...
So I would obviously have to change my docroot to instead of /htdocs it would be /htdocs/myprojects/someapp the problem is...whenever I need to work on someapp_version3.4 I would need to again change the docroot...
So I wonder...is it possible to specify a docroot using .htaccess??? That way depending on which directory I start, Apache assume the local docroot instead of the default....and I think I just answered my own question there...as I can't see that being technically possible...![]()
bummer
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Windows has an etc/hosts file to (it's in the system folder)Hockey wrote:Bam...perfect...I got everything working how I expected...
Couple more questions...
I get the Apache config directives and how they work...sorta...but the HOSTS file...is that part of Apache or part of the default linux install...is it's purpose basically to act as a local DNS???
YesHockey wrote: So I could in theory I could bind my local loopback address: 127.0.0.1 to a domain like pooptest.com and whenever I entered http://pooptest.com it would act as localhost???
/etc/hosts is there on all linux/unix systems. I'd be amazed if anybody ventured away from that standard. Mac OS X is based in Darwin (a UNIX system) and they have oddly decided to go with /private/etc/hosts but then Mac is sort of an exception anyway.Hockey wrote: If you could just yes or no me on that one...it would certainly clear everything up a little...or better yet explain it...as the more I read about how it all works from the more sources I find the better off I am
Secondly...if I needed to programatically locate that HOSTS file...is there a way?
I'm sure I've mentioned it a few times in this thread, VirtualHosts is what you need. Apache can determine different doc roots based upon the domain name used to access it.Hockey wrote: Also, one more thing...
Under localhost I have a directory setup like:
docroot/myprojects
docroot/tempprojects
docroot/payprojects
I typically work under the /myprojects directory which is further broken up:
cms/
crm/
kbase/
and so on...
Right now, the project I'm working with is accessed via HTTP as: http://localhost/myprojects/someapp and I have mapped a forums subdomain to localhost so despite being for the above someapp it's actually accessed as: http://forums.localhost
It works, but looks awkward...
So I would obviously have to change my docroot to instead of /htdocs it would be /htdocs/myprojects/someapp the problem is...whenever I need to work on someapp_version3.4 I would need to again change the docroot...
So I wonder...is it possible to specify a docroot using .htaccess??? That way depending on which directory I start, Apache assume the local docroot instead of the default....and I think I just answered my own question there...as I can't see that being technically possible...![]()
bummer
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
Could you take a look at my Apache config for virtual hosts please?
At the moment I have setup a virtual host on my machine but it never redirects to the virtual hosts root directory.
I have restarted apache since changes were made and I have received no error messages.
Any ideas appreciated.
Regards,
At the moment I have setup a virtual host on my machine but it never redirects to the virtual hosts root directory.
Whether I goto stesbox.co.uk or test.stesbox.co.uk, it always redirects me to the contents of /var/www/html.<VirtualHost *>
ServerName stesbox.co.uk
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *>
ServerName test.stesbox.co.uk
DocumentRoot /var/www/html/test
</VirtualHost>
I have restarted apache since changes were made and I have received no error messages.
Any ideas appreciated.
Regards,
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Do you have this line anywhere in your httpd.conf?impulse() wrote:Could you take a look at my Apache config for virtual hosts please?
At the moment I have setup a virtual host on my machine but it never redirects to the virtual hosts root directory.
Whether I goto stesbox.co.uk or test.stesbox.co.uk, it always redirects me to the contents of /var/www/html.<VirtualHost *>
ServerName stesbox.co.uk
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *>
ServerName test.stesbox.co.uk
DocumentRoot /var/www/html/test
</VirtualHost>
I have restarted apache since changes were made and I have received no error messages.
Any ideas appreciated.
Regards,
Code: Select all
NameVirtualHost *