Question

I have many services running on the same machine, one of them using SSL, let's say "c3po.com". The url for my servers are https://c3po.com, http://r2d2.com and http://jarjar.com.

The problem is, if I type https://r2d2.com apache redirects me to https://c3po.com, without even changing the url. In other words, I will be seeing c3po service, with my browser showing http://r2d2.com.

I understand that when Apache can't exactly match a vhost it uses the first one loaded that matches the ip:port, so as there is no:

<VirtualHost *:443>
    ServerName r2d2.com
    ...

It will pick up the only vhost on :443 found, which is:

<VirtualHost *:443>
    ServerName c3po.com
    ...

What I really want is that when the user types https://r2d2.com or https://jarjar.com an error page is shown up, because those services (with ssl enabled over http) simply doesn't exist! How can I achieve that?

Was it helpful?

Solution

Check that

NameVirtualHost *:443

is enabled in your main config. Then create a VirtualHost that listens on port 443 with your error page, and create another VirtualHost with the config for c3po.com. If any user resolves a name to the IP of your server (which they will for all sites), they will go to the default site unless they're going to c3po.

Something along the lines of the following should work:

Default:

<VirtualHost *:443>
  ServerName _default_https
  DocumentRoot /path/to/error/page
  <Directory /path/to/error/page>
    ...
  </Directory>
</VirtualHost>

c3po:

<VirtualHost *:443>
  ServerName c3po.com
  ServerAlias www.c3po.com
  DocumentRoot /path/to/c3po
  <Directory /path/to/c3po>
    ...
  </Directory>
</VirtualHost>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top