Search code examples
apachevirtualhosts

Apache Virtual Hosts Strange Behavior


I have a virtual - host file containing the following:

# lc.glsamcrm.com
#

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName lc.glsamcrm.com
    ServerAlias glsamcrm.com
    DirectoryIndex index.html
    DocumentRoot /var/www/glsamcrm/htdocs/  
    ErrorLog /var/www/glsamcrm/logs/error.log
    CustomLog /var/www/glsamcrm/logs/access.log combined

    ServerAdmin [email protected]
    ServerName crm.glstest.com
    ServerAlias crm.glstest.com
    DirectoryIndex index.html
    DocumentRoot /var/www/glsamcrm_prod/htdocs/ 
    ErrorLog /var/www/glsamcrm_prod/logs/error.log
    CustomLog /var/www/glsamcrm_prod/logs/access.log combined   
</VirtualHost>

when I point my browser to lc.glsamcrm.com all works fine. When I point my browser to crm.glstest.com, I get the "THIS WORKS" index page located in the etc/www/ folder. What is going on?


Solution

  • You need two separate VirtualHost directives. This is because you can only put one ServerName, DocumentRoot, and a few others per VirtualHost.

    <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName lc.glsamcrm.com
        ServerAlias glsamcrm.com
        DirectoryIndex index.html
        DocumentRoot /var/www/glsamcrm/htdocs/  
        ErrorLog /var/www/glsamcrm/logs/error.log
        CustomLog /var/www/glsamcrm/logs/access.log combined
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName crm.glstest.com
        ServerAlias crm.glstest.com
        DirectoryIndex index.html
        DocumentRoot /var/www/glsamcrm_prod/htdocs/ 
        ErrorLog /var/www/glsamcrm_prod/logs/error.log
        CustomLog /var/www/glsamcrm_prod/logs/access.log combined   
    </VirtualHost>