Subdomains and Apache

Discussion in 'Server Operation' started by redstar, Apr 21, 2005.

  1. redstar

    redstar New Member

    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
     
  2. jojo

    jojo New Member HowtoForge Supporter

    You can do it with the ServerAlias directive. A little example:

    Code:
    <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
     
  3. Dutzzu

    Dutzzu New Member

    hm...i have a question here ...

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

    Code:
    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:eek: .... 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 ) :


    Code:
    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 :eek: .... witch of this two codes is better ?
     
  4. falko

    falko Super Moderator ISPConfig Developer

    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?

    They do pretty much the same.
     
  5. Dutzzu

    Dutzzu New Member

    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

    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 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 :)
     
    Last edited: May 27, 2006
  6. falko

    falko Super Moderator ISPConfig Developer

    I'd put

    Code:
    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.
     
  7. unkn0wn

    unkn0wn New Member

    must i change some dns record for subdomain? or just edit httpd.conf
     
  8. falko

    falko Super Moderator ISPConfig Developer

    Your DNS records for the subdomains must point to the correct IP address.
     
  9. Dutzzu

    Dutzzu New Member

    Should i delete something from the start of the document ? or just paste that code at the end ? :confused:
     
  10. falko

    falko Super Moderator ISPConfig Developer

    Paste the code at the end and comment out those directives if they are somewhere else in the file.
     
  11. Dutzzu

    Dutzzu New Member

    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
     
  12. Dutzzu

    Dutzzu New Member

    falko it's not working to put that code at the end of httpd.conf file :(

    i've put this
    Code:
    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 :)
     
  13. falko

    falko Super Moderator ISPConfig Developer

  14. Dutzzu

    Dutzzu New Member

    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 :
    Code:
    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 =))
     
  15. falko

    falko Super Moderator ISPConfig Developer

    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?

    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?
     
  16. Dutzzu

    Dutzzu New Member

    Last edited: Jun 10, 2006
  17. falko

    falko Super Moderator ISPConfig Developer

    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.
     
  18. tommytomato

    tommytomato New Member

    I too is looking at creating subdomains

    I've given it ago only to get an error

    Code:
    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
     
  19. falko

    falko Super Moderator ISPConfig Developer

    What error did you get?
    What's the output of
    Code:
    apache2 -t
    ?

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

    tommytomato New Member

Share This Page