1

I have an Apache server that will be serving up a few sites (all from the same IP address).

Site A must be accessible via HTTP and HTTPS.

Site B must only be accessible via HTTP - it cannot be accessed via https.

Site A works fine, but Site B is giving me trouble. When a user attempts to access https://SiteB they get redirected to https://SiteA.

The config for Site A looks like this:

# 001-SiteA.conf:
<VirtualHost *:80>
  ServerName SiteA
  ServerAlias SiteA
  # ...
</VirtualHost>

# 001-SiteA-SSL.conf:
<VirtualHost *:443>
  ServerName SiteA
  ServerAlias SiteA
  # ...
</VirtualHost>

# 002-SiteB.conf
<VirtualHost *:80>
  ServerName SiteB
  ServerAlias SiteB
  # ...
</VirtualHost>

What is preferred is that the user get a 404 error or an empty page or something - but definitely not the content of SiteA.

Why is https://SiteB redirecting users to https://SiteA and how can I stop that?

  • What are your other virtual hosts, especially your :443 ones? You may have to create a dummy virtual host for SiteB:443. – Stephen Ostermiller Jun 19 '17 at 17:07
  • @StephenOstermiller: I've added more details to the question. – FrustratedWithFormsDesigner Jun 19 '17 at 17:15
  • 1
    Apache treats the first virtual host for each port as the default. The fact that siteB doesn't have a :443 virtual host configured means that requests for it will use siteA's. – Stephen Ostermiller Jun 19 '17 at 17:17
  • Even though the server name doesn't match? Seriously? If this is defined behaviour, I might need a link to reference, to prove to someone here that I'm not crazy. – FrustratedWithFormsDesigner Jun 19 '17 at 17:24
  • 1
    Keep in mind that Apache server software predates virtual hosts. This is holdover from the days when there could only be one web site per server and it was expected to respond to any and all host names. – Stephen Ostermiller Jun 19 '17 at 17:42
1

The Apache documentation for name based virtual hosts states (emphasis is theirs):

The default name-based vhost for an IP and port combination

If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.

Because you don't have a virtual host defined for siteB:443 it is defaulting to siteA:443 because it is the first one matching the IP address and port number.

There are two ways to solve this:

  1. Create a virtual host for siteB:443
  2. Create virtual hosts to handle unknown host names. Have them return error codes. Have them come first in the list by naming the config files like 0000-default-site.conf and 0000-default-site-ssl.conf

I'd recommend the default site solution, otherwise SiteA will be served up for any random host name that is pointed to the server.

  • Actually, I'm finding that using a default config in 000-default.conf is also capturing traffic to SiteA and sending that to the default page. :( – FrustratedWithFormsDesigner Jun 20 '17 at 13:31
  • Check that you don't have a real ServerName or ServerAlias in the default and siteA.conf has the correct ServerName. Also make sure 000-default comes first, If you already have conf with three zeros, use four. – Stephen Ostermiller Jun 20 '17 at 14:00
  • I checked those things, but since other people are using this server now (it's a test server, but other people test other things on it), I've gone back to Option 1: creating a virtual host for SiteB:443. I'd like to figure out why the default sites didn't work, but no time for it today probably. – FrustratedWithFormsDesigner Jun 20 '17 at 14:17
  • The default config for virtualhost *:443 does NOT have a ServerName/ServerAlias. I renamed it to 999-default-ssl.conf and now SiteA works properly for http and https but SiteB:443 goes to SiteA:443, if I don't have an explicit virtualhost defined for SiteB:443. – FrustratedWithFormsDesigner Jun 20 '17 at 15:59
  • at 999 it will come last and not work. Try it first with ServerName localhost. – Stephen Ostermiller Jun 20 '17 at 16:35

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.