Why is my Apache virtualhost showing the default page for Apache?

24,779

Solution 1

You need to modify the root directory for your virtual host. Otherwise you will have a subdomain which will show exactly the same data as your main domain.

For subdomain.domain.com you should set the DocumentRoot of the subdomain to DocumentRoot /var/www/page1 and for subdomain2.domain.com to DocumentRoot /var/www/page2 etc.

Check out the examples

Solution 2

Your configuration should look like this:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName    domain.com
  ServerAlias   www.domain.com
  DocumentRoot  /var/www/ivan # absolute path to your web root
</VirtualHost>

<VirtualHost *:80>
  ServerName    subdomain1.domain.com
  ServerAlias   www.subdomain1.domain.com
  DocumentRoot  /var/www/sub1 # absolute path to your web root
</VirtualHost>

<VirtualHost *:80>
  ServerName    subdomain2.domain.com
  ServerAlias   www.subdomain2.domain.com
  DocumentRoot  /var/www/sub2 # absolute path to your web root
</VirtualHost>
Share:
24,779

Related videos on Youtube

IvanAK
Author by

IvanAK

Updated on September 18, 2022

Comments

  • IvanAK
    IvanAK over 1 year

    I was wondering if im doing something wrong or what ? I have subdomain pointing to my server IP ( public ip of my server ) but when ever i go to my subdomain it show me the default page of Apache. Yes I'm using name virtual hosts but still nothing ...

    For now i have put the page in the html directory, and it works ok but i think that is not the solution. And yes i can point my subdomain to subdomain.domain.com/thepage but this i don't want to do. And here is what i have in conf. part

        NameVirtualHost *:80
        <VirtualHost *:80>
        ServerName    subdomain.domain.com
        DocumentRoot  /var/www/
        ServerAlias   www.subdomain.domain.com
        </VirtualHost>
    

    Any suggestion ?


    This is what i've got ..

    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName    domain.com
    DocumentRoot  /var/www/ - here is domain.com ( there is directory named ivan )
    ServerAlias   www.domain.com
    </VirtualHost>
    
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName    subdomain1.domain.com
    DocumentRoot  /var/www/ - and here is subdomain1.domain.com - directory named sub1
    ServerAlias   www.subdomain1.domain.com
    </VirtualHost>
    
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName    subdomain2.domain.com
    DocumentRoot  /var/www/ - and here is subdomain2.domain.com - directory named sub2 ( And I don't know if they need to be the same name as the address or ??? sometimes I'm confused about that. )
    ServerAlias   www.subdomain2.domain.com
    </VirtualHost>
    

    And all i got is default page of Apache ...

    • b13n1u
      b13n1u over 10 years
      Are you sure you want to have the same DocumentRoot as the main domain ? (I assume that /var/www is used by your main domain also)
    • ETL
      ETL over 10 years
      Not sure I understand what you are saying: when you browse to "subdomain.domain.com" you are not getting the files from /var/www ?
    • IvanAK
      IvanAK over 10 years
      ETL- Yes .. when i go to subdomain.domain.com i get the default page from apache. b13n1u - I like, when i go to subdomain.domain.com to show me the page that is in /var/www/page1 ( for example ) and when i go to subdomain2.domain.com or domain.com to show me the page that is in /var/www/page2 etc ...
    • b13n1u
      b13n1u over 10 years
      For subdomain.domain.com you should set the DocumentRoot of the subdomain to DocumentRoot /var/www/page1 and for subdomain2.domain.com DocumentRoot /var/www/page2 Otherwise your subdomain will show exactly the same data as your main domain. Check out the examples
    • Michael Hampton
      Michael Hampton over 10 years
      @b13n1u That sounds like the answer; you should probably go below and make it an answer.
    • Dhananjay Yadav
      Dhananjay Yadav almost 4 years
      probably you have missed "sudo service apache2 restart"
  • IvanAK
    IvanAK over 10 years
    i will try this and tell what iv done ....