PDA

View Full Version : Subdomains and Apache


redstar
21st April 2005, 17:36
A quick newbie-question: how do you set up subdomains in Apache? What I want to do is this:

I have a web site www.domain.com. Now I want to create a subdomain sub.domain.com, and when I enter it in my browser, I want to go to the same web site (www.domain.com).

RedStar

jojo
22nd April 2005, 10:47
You can do it with the ServerAlias directive. A little example:

<VirtualHost aaa.bbb.ccc.ddd>
ServerName www.domain.com
ServerAdmin webmaster@domain.com
DocumentRoot /path/to/your/document_root
ServerAlias sub.domain.com
</VirtualHost>

Jojo

Dutzzu
27th May 2006, 10:40
hm...i have a question here ...

i found on net a similar code with the one gived by jojo

Listen 80
NameVirtualHost *

<VirtualHost *>
ServerName www.domain.com
DocumentRoot /home/httpd/htdocs/
</VirtualHost>

<VirtualHost *>
ServerName subdomain.domain.com
DocumentRoot /home/httpd/htdocs/subdomain/
</VirtualHost>



and i'm sure that it's gonna work ...

but now a noomb question:o .... where do i paste this code in httpd.conf ?

The begining of my httpd.conf looks like this ( i won't paste all file it's to large ) :


Listen 80
ServerRoot "/www/Apache2"
DocumentRoot "/www/webroot"

ServerName localhost:80
ServerAdmin admin@localhost

ServerSignature On
ServerTokens Full

DefaultType text/plain
AddDefaultCharset ISO-8859-1


Can anybody show me how should i modify the file ? :D

That's all :) Thanq

ps : and another noomb question :o .... witch of this two codes is better ?

falko
27th May 2006, 13:34
but now a noomb question:o .... where do i paste this code in httpd.conf ?
This normally goes near the end of your httpd.conf. There should be an example section about virtual hosts. But it might also be in some included file. Which distribution do you use?

ps : and another noomb question :o .... witch of this two codes is better ?
They do pretty much the same.

Dutzzu
27th May 2006, 21:52
First of all than'q for answering me falko

Now ... i've got the apache instalation from http://www.devside.net/web/server/free/download ( setup 1.16 ) ...

And about httpd.conf file ... it doesn't have any exemple ... i think it's not a very popular version of apache :( in all forums i looked the httpd.conf file looks different :( I hope that's not a problem :(

I think it's easyer if i put the file ... and if u have time & wish to help me ... to solve it easyer . So here's the file (http://freewebs.com/dutzzu/danutza/httpd.conf)

And about the exemple u saied that it should be ... i found one in other file ( witch is in the same folder with httpd.conf ) named " httpd.default.conf " ... it has a lil' example at the end of the file .... here'is the file (http://freewebs.com/dutzzu/danutza/httpd.default.conf) If this is what i searched i have to delet " # " before the example and replace it with the code i entered in first message ?

Thank you again for your time :)

falko
28th May 2006, 22:49
I'd put

Listen 80
NameVirtualHost *

<VirtualHost *>
ServerName www.domain.com
DocumentRoot /home/httpd/htdocs/
</VirtualHost>

<VirtualHost *>
ServerName subdomain.domain.com
DocumentRoot /home/httpd/htdocs/subdomain/
</VirtualHost>

at the end of your httpd.conf and restart Apache.

unkn0wn
29th May 2006, 09:30
must i change some dns record for subdomain? or just edit httpd.conf

falko
29th May 2006, 15:51
Your DNS records for the subdomains must point to the correct IP address.

Dutzzu
4th June 2006, 20:59
Should i delete something from the start of the document ? or just paste that code at the end ? :confused:

falko
5th June 2006, 14:25
Paste the code at the end and comment out those directives if they are somewhere else in the file.

Dutzzu
9th June 2006, 17:31
i have a new problem :(

i buyed a .ro domain and i have a problem with nameserver

i need a program that makes nameserver on windows XP

does anybody know such soft ??

I know that this is not the right topic to post this question but i didn't want to open a new topic

Than'q

Dutzzu
9th June 2006, 21:43
falko it's not working to put that code at the end of httpd.conf file :(

i've put this
Listen 80
NameVirtualHost *

<VirtualHost *>
ServerName dutzzu.ro
ServerRoot "/www/Apache2"
DocumentRoot "/www/webroot"
</VirtualHost>

<VirtualHost *>
ServerName poze.dutzzu.ro
DocumentRoot "/www/webroot/poze"
</VirtualHost>

at the start of the file but it's not working too :(

i want to make http://dutzzu.ro/poze to beacame http://poze.dutzzu.ro

any ideeas ?

Best regards ,
Dutzzu

ps : i've solve the problem with the name'server ; a friend gived me a free software witch solved my probelm :)

falko
9th June 2006, 23:14
falko it's not working to put that code at the end of httpd.conf file :(What exactly is not working? Any errors?


i want to make http://dutzzu.ro/poze to beacame http://poze.dutzzu.ro

any ideeas ?

You can either redirect your users with a PHP script like this:
<?php
header("Location: http://poze.dutzzu.ro");
exit;
?>
or you use Apache rewrite rules: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Dutzzu
9th June 2006, 23:28
to the first question .... or i don't get any erorr but it's not working ... or i had an error msg with looked like this ( after i stopped and tryed to restart it again :

The Apache service could not be started
A service specific error occurred: 1
More help is avaible by typing NET HELPMSG 3547

and if i type " net helpmsg 3547 it tells me " Reffer to the help or documentation for that service to determine the problem "

Now ... i wasn't explicit enought ... i want to make avaible http://poze.dutzzu.ro .... it doesn't working now ... how can i make this subdomain to work ?



thank you again for you time falko :)

ps : that last url u gived me is in chinese i think ... don't understand it at all =))

falko
10th June 2006, 00:03
to the first question .... or i don't get any erorr but it's not working ... or i had an error msg with looked like this ( after i stopped and tryed to restart it again :

The Apache service could not be started
A service specific error occurred: 1
More help is avaible by typing NET HELPMSG 3547

and if i type " net helpmsg 3547 it tells me " Reffer to the help or documentation for that service to determine the problem "Never seen a message like that. Which distribution do you use? Did you follow any of the "Perfect Setup" guides on HowtoForge to set the system up? Anything in Apache's error log?

Now ... i wasn't explicit enought ... i want to make avaible http://poze.dutzzu.ro .... it doesn't working now ... how can i make this subdomain to work ?Do you want that domain to be a web site for itself or do you want to point that domain to an existing web site?

Dutzzu
10th June 2006, 00:14
Well ... the ideea is that i buyed a .ro domain ( http://dutzzu.ro )

and i know how to make subdomains like this : http://dutzzu.ro/radio .... but i'd like this to apear like this : http://radio.dutzzu.ro

this is all i want to do :D

ps : as u realise it;s the same problem with http://dutzzu/poze ... witch i want to be : http://poze.dutzzu.ro

:)

falko
10th June 2006, 21:17
and i know how to make subdomains like this : http://dutzzu.ro/radio .... but i'd like this to apear like this : http://radio.dutzzu.ro

Do you want radio.dutzzu.ro to be a completely new web site, or just to point to the existing dutzzu.ro web site?
Anyway, first of all you must create radio.dutzzu.ro in DNS.

tommytomato
20th June 2007, 01:49
I too is looking at creating subdomains

I've given it ago only to get an error

oot@rockinghamgateway:/etc/apache2/sites-enabled# /etc/init.d/apache2 reload
* Reloading apache 2.0 configuration... [Tue Jun 19 21:14:45 2007] [warn] VirtualHost cooper.rockinghamgateway.com:0 overlaps with VirtualHost cooper.rockinghamgateway.com:0, the first has precedence, perhaps you need a NameVirtualHost directive
[ ok ]

have you got a howto on creating subdomains :confused:

any one care to explain how its done.

why did Apache change so much or has it changed, I was use too the way tinysofa did it.

I added my subs to the end of the httpd.conf file

TT

falko
20th June 2007, 15:44
What error did you get?
What's the output of apache2 -t?

If you like you can add your vhosts at the end of /etc/apache2/apache2.conf.

tommytomato
20th June 2007, 15:48
it says its ok
root@rockinghamgateway:~# apache2 -t
Syntax OK

I think i worked out the subdomains

found a link on Ubuntu
Not sure if its the correct way, but i followed what this person said

http://ubuntuforums.org/showthread.p...ight=subdomain

is a2ensite the same as linking it :confused:

opps, can i have a live test please

does the subdomain http://linux.rockinghamgateway.com work, it does my end.

TT

falko
21st June 2007, 16:32
is a2ensite the same as linking it :confused: Yes.


does the subdomain http://linux.rockinghamgateway.com work, it does my end.

TT
It's not working for me. The site cannot be found.
Is 58.7.0.171 the correct IP address?

mh1:~# dig linux.rockinghamgateway.com

; <<>> DiG 9.2.1 <<>> linux.rockinghamgateway.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15555
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;linux.rockinghamgateway.com. IN A

;; ANSWER SECTION:
linux.rockinghamgateway.com. 3560 IN A 58.7.0.171

;; Query time: 57 msec
;; SERVER: 213.191.92.84#53(213.191.92.84)
;; WHEN: Thu Jun 21 16:22:56 2007
;; MSG SIZE rcvd: 61

tommytomato
22nd June 2007, 01:26
thanks

I know its not working because i have the server off, by the time you get around to viewing the link, I've probley turn it off and i'm out to work ;)

TT

Dutzzu
22nd June 2007, 13:55
tks for help falko :D

i have a new question now: if i want to host 2 domains on a single server, what do i have to change in httpd.conf ?!? just paste a code similary like that for virtual host ?!?
smt like this ( if i have dutzzu.ro, and now i want to add another domain - example.ro )


Listen 80
NameVirtualHost *

<VirtualHost *>
ServerName dutzzu.ro
DocumentRoot /www/webroot
</VirtualHost>

<VirtualHost *>
ServerName example.ro
DOcumentRoot /www/webroot/example.ro
</VirtualHost>



Is this corect ? or i have to past smth else ( another code ) somwhere else ?

falko
23rd June 2007, 21:03
Looks ok. But you can find more information here: http://httpd.apache.org/docs/2.0/vhosts/name-based.html

commanderxai
19th October 2007, 06:28
Since this is along the same lines how would one accomplish a compound subdomain.

Example: http://sub1.sub2.sub3.host.tld/

in my <VirtualHost> Tag this is what I listed as the primary data:


ServerAdmin noc@xainet.com
ServerName www.ebarg.com
ServerAlias ebarg.com *.*.*.*.ebarg.com *.*.*.ebarg.com *.*.ebarg.com *.ebarg.com
DocumentRoot /my/path/to/root/


Obviously this wont work (already tried). httpd does not fault, but it won't let me us any more than one domain. I am sure it is possable though because you see it on government websites alot (course maybe it is a government thing).

Any ideas?

commanderxai
19th October 2007, 08:06
Hey, I figured it out to anyone who is interested.


ServerAdmin noc@xainet.com
ServerName www.ebarg.com
ServerAlias ebarg.com "^(a-zA-Z0-9_.)+$".ebarg.com *.ebarg.com
DocumentRoot /my/path/to/root/


The last ServerAlias directive is redundant, but I left it in there anyway.

Maybe someone can find this handy.

rul3z
31st October 2008, 15:16
Your DNS records for the subdomains must point to the correct IP address.

What if you are using Dynamic DNS? Who shall you point the subdomain to the correct IP?

Isn't there any work around?

falko
1st November 2008, 16:34
You can use CNAME records that point to your dyndns.org address.

rul3z
1st November 2008, 19:13
You can use CNAME records that point to your dyndns.org address.

Yes actually I finally managed to figure that out yesterday and sorry for not saying that here. I found it in the dyndns.org forum.

Thanks falko