1

I am a newbie to apache and server setup. I am migrating several sites from GoDaddy to a DigitalOcean VPS droplet. I am moving my first site over (a Wordpress install) and am having some trouble with VirtualHost. Here is the configs:

<VirtualHost *:80>
  ServerName domain.com
  ServerAlias www.domain.com
  DocumentRoot /var/www/html/domain.com
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Heres the thing, I have a www alias set up in the domain name records, and www.domain.com points correctly to the site, but domain.com points to the root var/www/html, not the subdirectory where the site is. I've searched for far too long, but every tutorial and forum seems to provide the same code I currently have configured. What am I doing wrong? I want to make sure it all works correctly before I take the next step of installing an SSL, but I am spinning my wheels at the moment.

ncox85
  • 75
  • 1
  • 9
  • 1
    Turns out that the default configuration was overriding my virtual host. I configured the default to point to the primary domain, and all is working now. – ncox85 Mar 02 '17 at 23:37

1 Answers1

2

The correct way to set up a virtual host is:

<VirtualHost *:80>
        ServerAdmin admin@domain.com
        DocumentRoot /path/to/the/directory
        DirectoryIndex index.html index.php
        ServerName domain.com
        ServerAlias www.domain.com
        ErrorLog ${APACHE_LOG_DIR}/domain.com.error.log
        CustomLog ${APACHE_LOG_DIR}/domain.com.access.log combined
        <Directory /path/to/the/directory>
                Options -Indexes
                Options FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>
Shakti Phartiyal
  • 6,156
  • 3
  • 25
  • 46
  • Thank you for responding. I updated the conf file to match this example. It was still not working, but I just realized I didn't restart apache before I left the house this morning. I assume it is always required to restart after editing these files? – ncox85 Mar 02 '17 at 14:39
  • @ncox85 Kindly approve the answer if it resolves your query. – Shakti Phartiyal Apr 19 '17 at 11:41