Why is my Apache VirtualHost directing to the wrong VirtualHost?

Posted November 24, 2020 1.2k views
ApacheDNSUbuntu 18.04DigitalOcean Droplets

On an existing wordpress-installed droplet, I am installing a new wordpress instance (two wordpress installs in same droplet).

To do so, I followed the answer by ryanpq on this thread:

Similar to the commenters on that thread, my newer site redirects to my existing site (even after changing the DocumentRoot and Directory appropriately).

Here are my configs:

Within /etc/apache2/sites-enabled, I have 4 files: 000-default-le-ssl.conf 000-default.conf example1.conf example2.conf

000-default.conf andexample1.conf` are copies.

example1.conf looks like so:

# Added to mitigate CVE-2017-8295 vulnerability
UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin webmaster@localhost


        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride None
            Require all granted

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

example2.conf looks like so:

<VirtualHost *:80>


        DocumentRoot /var/www/example2

        <Directory /var/www/example2/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

my directory structure looks like /var/www/html and /var/www/example2

Within the control panel of my DO account, I created a new project for my newly acquired domain name.

I created new A and CNAME records. The A record points to the IP address of the older, existing, site (so, directs to 128....)

Additional: I noticed while following the user ryanpq’s answer, that the wordpress install I did only had a wp-config-sample.php, so I copied that file, named it wp-config.php and filled it in with the database info.

What am I missing?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there @theindiman,

The configuration looks all correct. It is possible that the permissions of the /var/www/example2 are not correct. What you need to do is make sure that the Apache user has read and write permissions to that folder:

  • sudo chown www-data:www-data /var/www/example2

Also I could suggest checking your Apache error log for more information:

  • sudo tail -100 /var/log/apache2/error.log

And one more thing, is the example2com site a copy of the original site or a fresh new WordPress installation?


  • Thank you for the response.

    the particular chmod command you gave as an example did returns chmod: invalid mode: ‘www-data:www-data’

    But I did run this: chown -Rf www-data.www-data /var/www/example2; from the linked thread.

    The error log does not return anything out of the ordinary:

    [Tue Nov 24 07:54:32.597219 2020] [core:notice] [pid 1520] AH00094: Command line: '/usr/sbin/apache2'
    [Tue Nov 24 07:57:18.638256 2020] [mpm_prefork:notice] [pid 1520] AH00169: caught SIGTERM, shutting down
    [Tue Nov 24 07:57:18.776831 2020] [mpm_prefork:notice] [pid 1566] AH00163: Apache/2.4.29 (Ubuntu) OpenSSL/1.1.1d configured -- resuming normal operations
    [Tue Nov 24 07:57:18.776923 2020] [core:notice] [pid 1566] AH00094: Command line: '/usr/sbin/apache2'

    For the WP install, I followed these instructions also from the linked thread:

    mkdir /var/www/wordpress2;
    wget -O /tmp/wordpress.tar.gz;
    tar -zxf /tmp/wordpress.tar.gz  -C /tmp;
    mv -f /tmp/wordpress/* /var/www/wordpress2;

    so, a fresh installation. Still no luck.

    Additional info: I bought the new domain name a few hours ago.. It isn’t likely that that’s the reason, is it? I would imagine I wouldn’t be getting a redirect if the reason was due to unpropogated domain.

    • Hi there @theindiman,

      The command needs to be chown rather than chmod:

      • sudo chown www-data:www-data /var/www/example2

      The chown command changes the owner and the group of the files and folders, and the chmod changes the permissions.

      Let me know how it goes!

  • I just checked error log again, and got something new:

    [Tue Nov 24 12:53:53.100835 2020] [authz_core:error] [pid 1690] [client] AH01630: client denied by server configuration: /var/www/html/.htaccess.bak
    [Tue Nov 24 12:53:53.240080 2020] [authz_core:error] [pid 1692] [client] AH01630: client denied by server configuration: /var/www/html/.htaccess.sample
    [Tue Nov 24 12:53:53.378340 2020] [authz_core:error] [pid 1691] [client] AH01630: client denied by server configuration: /var/www/html/.htaccess
    [Tue Nov 24 12:53:53.518986 2020] [authz_core:error] [pid 1998] [client] AH01630: client denied by server configuration: /var/www/html/.htpasswd

    My .htaccess was last modified for my original site: example1.

    Here’s the .htaccess:

    # BEGIN WpFastestCache
    # Modified Time: 03-09-20 6:22:49
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} =on
    RewriteCond %{HTTP_HOST} ^
    # Start WPFC Exclude
    # End WPFC Exclude
    # Start_WPFC_Exclude_Admin_Cookie
    RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=simon
    # End_WPFC_Exclude_Admin_Cookie
    RewriteCond %{HTTP_HOST} ^
    RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit|WP_FASTEST_CACHE_CSS_VALIDATOR|Twitterbot|LinkedInBot|WhatsApp|Mediatoolkitbot)
    RewriteCond %{HTTP_USER_AGENT} !(WP\sFastest\sCache\sPreload(\siPhone\sMobile)?\s*Bot)
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{REQUEST_URI} !(\/){2}$
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{QUERY_STRING} !.+
    RewriteCond %{HTTP:Cookie} !wordpress_logged_in
    RewriteCond %{HTTP:Cookie} !comment_author_
    RewriteCond %{HTTP:Cookie} !safirmobilswitcher=mobil
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or]
    RewriteCond /var/www/html/wp-content/cache/all/$1/index.html -f
    RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L]
    <FilesMatch "index\.(html|htm)$">
    AddDefaultCharset UTF-8
    <ifModule mod_headers.c>
    FileETag None
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT"
    # END WpFastestCache
    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    These settings are, I’m assuming, for example1 since they were only modified after and before I installed

    Could this have anyhting to do with my problems?