Mobile app version of vmapp.org
Login or Join
Ravi8258870

: With several sites on the same server and different rules for HTTP/HTTPS a non-secure site is getting redirected to a different secure one I have an Apache server that will be serving up a

@Ravi8258870

Posted in: #Apache2 #Https

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 SiteB they get redirected to 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 SiteB redirecting users to SiteA and how can I stop that?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

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:


Create a virtual host for siteB:443
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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme