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.


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 /home/source/public_html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all

        ErrorLog /home/source/log/error_log
        TransferLog /home/source/log/access_log

I have also updated /etc/hosts to show:       localhost       productionserver       www.domain.com

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: www.yoursite.com

Browse to www.yoursite.com.

Hope this helps!


  • Thanks for the tips, a few steps you mentioned I had forgotten, but I'm still not able to access the site. – Webnet Aug 20 '10 at 16:40
NameVirtualHost *:80
<VirtualHost xxx.xxx.xxx.xxx:80>

Better yet, just use *:80 in the VirtualHost directive if you don't need (or care) to tie it to a specific IP address.

NameVirtualHost *:80
<VirtualHost *:80>
  • PS: it's common syntax that 'ServerName' should always be the first line inside the VirtualHost block for clarity. It's not a technical thing, but a human readable thing. – user15590 Aug 20 '10 at 0:55
  • Also, use tail on apache's log files when making request. – peelman Aug 20 '10 at 4:34
  • I'd prefer to stick with the IP address – Webnet Aug 20 '10 at 18:18

You only have www.domain.com in your hosts file and the server name is domain.com.

You can fix it by either adding www.domain.com after domain.com in your hosts file or adding this line after ServerName directive in apache configuration:

ServerAlias www.domain.com

Then reload apache configuration.

Thanks, -Kamil

  • I made that adjustment and reloaded apache, it didn't appear to have any effect. – Webnet Aug 20 '10 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.