Basic VirtualHost setup apache

apache-2.2virtualhost

I'm setting up my first virtual host but the domain is not working. I've sudo a2ensite SITENAME'd it and restarted apache but it's still not accessible. I've verified that the IP is correct because I'm currently logged into splunk via the IP.

update

I have my NameVirtualHost *:80 on apache2.conf. My updated VirtualHost configuration for the site is:

<VirtualHost xx.xxx.xxx.xxx:80>
        ServerName www.domain.com
        ServerAlias domain.com
        ServerAdmin email@gmail.com

        DocumentRoot /home/source/public_html/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/source/public_html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /home/source/log/error_log
        TransferLog /home/source/log/access_log
</VirtualHost>

I have also updated /etc/hosts to show:

127.0.0.1       localhost
127.0.1.1       productionserver
127.0.0.1       www.domain.com

Best Answer

What version of Apache are you using? If you are using version 2, the default VirtualHost configuration should serve you well. Use the following command to create a new VirtualHost:

$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/www.yoursite.com 

Edit directives using your favourite text editor:

$ gksudo gedit /etc/apache2/sites-available/www.yoursite.com

Activate your site:

$ sudo a2ensite www.yoursite.com

Reload Apache:

$ sudo /etc/init.d/apache2 reload

Update /etc/hosts file with IP address and domain name:

127.0.0.1 www.yoursite.com

Browse to www.yoursite.com.

Hope this helps!

Mike