Find the answer to your Linux question:
Results 1 to 2 of 2
Hey guys, having trouble with virtual hosts on my CentOS run Apache2 server. my httpd.conf is as follows (changed the domain and user names for security) Code: NameVirtualHost *:80 <VirtualHost ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    11

    Apache VirtualHost Help


    Hey guys, having trouble with virtual hosts on my CentOS run Apache2 server.

    my httpd.conf is as follows (changed the domain and user names for security)

    Code:
    NameVirtualHost *:80
    
    <VirtualHost *:80>
            DocumentRoot /home/user1/domain1.com/public_html
            ServerName domain1.com
            <Directory />
                    AllowOverride All
            </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
            DocumentRoot /home/user2/domain2.com/public_html
            ServerName domain2.com
            <Directory />
                    AllowOverride All
            </Directory>
    </VirtualHost>
    Now domain1.com shows the correct files however by going to domain2.com it is showing the files for domain1.com.....

    i tried in a different browser incase it was showing a cached page from a previous viewing but its not.

    Any suggestions ?

    Cheers.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,442
    the config looks ok.

    What comes to mind:
    Any servername, that is not explicitly written in the config will default to the first server.

    In your example:

    Code:
    domain2.com should return domain2.
    But 
    www.domain2.com will return domain1.
    To overcome that,
    you can use ServerAlias, together with wildcards.

    ie:
    Code:
    ServerName www.domain2.com
    ServerAlias domain2.com
    ServerAlias *.domain2.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •