2

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 protected]

        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

3 Answers 3

2

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

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

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>
</VirtualHost>
3
  • 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, 2010 at 0:55
  • Also, use tail on apache's log files when making request.
    – peelman
    Aug 20, 2010 at 4:34
  • I'd prefer to stick with the IP address
    – Ben
    Aug 20, 2010 at 18:18
0

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .