Why is my website serving the wrong content?

Linode Staff

I am hosting multiple domains on my Linode, but whenever I attempt to go to one domain, it's serving me the content of another domain. Is this a redirect issue? The URL doesn't change when I load the domain in my browser, but it's showing content for one of the other websites hosted on the Linode. I am running a LAMP stack on Debian.

1 Reply

Hey there!

It sounds to me like the issue you are experiencing is a misconfiguration with your Linode's virtual hosts file. If it's loading another domain that is hosted on the Linode, there are two places I would recommend checking in the domain files. First I would look for any wayward redirects that are moving example1.com to example2.com. Because the URL isn't changing, however, the more likely culprit is going to be the DocumentRoot for these domains.

I would recommend taking a look at the /etc/apache2/sites-available/ directory on your Linode to locate the .conf files for your individual domains. These will be the virtual host files. A virtual host file for example1.com, for example, would likely be named /etc/apache2/sites-available/example1.conf and look like the following:

<VirtualHost *:80>
    # The primary domain for this host
    ServerName example1.com
    # Optionally have other subdomains also managed by this Virtual Host
    ServerAlias example1.com *.example1.com
    DocumentRoot /var/www/html/example1.com/public_html
    <Directory /var/www/html/example1.com/public_html>
        Require all granted
        # Allow local .htaccess to override Apache configuration settings
        AllowOverride all
    </Directory>
    # Enable RewriteEngine
    RewriteEngine on
    RewriteOptions inherit

    # Block .svn, .git
    RewriteRule \.(svn|git)(/)?$ - [F]

    # Catchall redirect to www.example1.com
    RewriteCond %{HTTP_HOST}   !^www.example1\.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteRule ^/(.*)         https://www.example1.com/$1 [L,R]

    # Recommended: XSS protection
    <IfModule mod_headers.c>
        Header set X-XSS-Protection "1; mode=block"
        Header always append X-Frame-Options SAMEORIGIN
    </IfModule>
</VirtualHost>

A configuration file for example2.com would likely be named /etc/apache2/sites-available/example2.conf and look like the following:

<VirtualHost *:80>
  # The primary domain for this host
  ServerName example2.com
  # Optionally have other subdomains also managed by this Virtual Host
  ServerAlias example2.com *.example2.com
  DocumentRoot /var/www/html/example2.com/public_html
  <Directory /var/www/html/example2.com/public_html>
      Require all granted
      # Allow local .htaccess to override Apache configuration settings
      AllowOverride all
  </Directory>
  # Enable RewriteEngine
  RewriteEngine on
  RewriteOptions inherit

  # Block .svn, .git
  RewriteRule \.(svn|git)(/)?$ - [F]

  # Catchall redirect to www.example2.com
  RewriteCond %{HTTP_HOST}   !^www.example2\.com [NC]
  RewriteCond %{HTTP_HOST}   !^$
  RewriteRule ^/(.*)         https://www.example2.com/$1 [L,R]

  # Recommended: XSS protection
  <IfModule mod_headers.c>
      Header set X-XSS-Protection "1; mode=block"
      Header always append X-Frame-Options SAMEORIGIN
  </IfModule>
</VirtualHost>

Because the URL isn't changing when you load example1.com but it's serving the content of example2.com, I suspect the DocumentRoot for example1.com shows /var/www/html/example2.com/public_html instead of /var/www/html/example1.com/public_html. If you change that then reload Apache by running sudo systemctl reload apache2 I believe you should be good to go. You can read more about properly setting up Apache's virtual hosts for multiple domains at our Configure Worpress to run Multiple Domain guide.

I hope this helps!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct