Name based virtual hosts with SSL on Apache 2.2.3/CentOS 5.9

Hi I'm trying to serve one site with two subdomains, and both subdomains should be under SSL. I've purchased a wildcard SSL certificate and have it installed. In my vhosts file I have 5 definitions, www (80), app (80/443), and staging (80/443). All of the subdomains work under port 80.

Here's a snippet of my vhosts.conf file:

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
  ServerAdmin support@---
  ServerName app.---
  DocumentRoot /var/www/vhosts/---/app/www/
  ErrorLog /var/www/vhosts/---/app/log/error.log

  <Directory "/var/www/vhosts/---/app/www">
    Options Indexes FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  ServerAdmin support@---
  ServerName app.---
  DocumentRoot /var/www/vhosts/---/app/www/
  ErrorLog /var/www/vhosts/---/app/log/ssl.log

  SSLEngine ON
  SSLCertificateFile /etc/httpd/conf.d/ssl/---/ssl.crt
  SSLCertificateKeyFile /etc/httpd/conf.d/ssl/---/ssl.key
  SSLCertificateChainFile /etc/httpd/conf.d/ssl/---/intermediate.crt

  <Directory "/var/www/vhosts/---/app/www">
    Options Indexes FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin support@---
  ServerName staging.---
  DocumentRoot /var/www/vhosts/---/staging/www/
  ErrorLog /var/www/vhosts/---/staging/log/error.log

  <Directory "/var/www/vhosts/---/staging/www">
    Options Indexes FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  ServerAdmin support@---
  ServerName staging.---
  DocumentRoot /var/www/vhosts/---/staging/www/
  ErrorLog /var/www/vhosts/---/staging/log/ssl.log

  SSLEngine ON
  SSLCertificateFile /etc/httpd/conf.d/ssl/---/ssl.crt
  SSLCertificateKeyFile /etc/httpd/conf.d/ssl/---/ssl.key
  SSLCertificateChainFile /etc/httpd/conf.d/ssl/---/intermediate.crt

  <Directory "/var/www/vhosts/---/staging/www">
    Options Indexes FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

If I change this line:

<VirtualHost *:443>

To:

<VirtualHost SERVER_IPADDRESS:443>

The first definition will work as expected and use the correct certificate. When I restart Apache I receive a message in the terminal stating there's a duplicate entry and only the first will be used.

With the conf as it is above I don't receive any errors or warnings in the terminal, but I have seen this in Apache's log:

[warn] Init: You should not use name-based virtual hosts in conjunction with SSL!!

From what I've read online that warning is expected and shouldn't be a problem.

Running configtest shows Syntax OK.

It seems the problem is named virtual hosts with SSL. I've checked 3 guides online and tried a variety of things (using *.domain.com as ServerName for both, app.domain.com as ServerAlias), subdomains as the directive (app.domain.com:443) but can't figure out the right combination to serve each subdomain under both 80 and 443 using only one IP address.

I know it's possible. Any ideas on what I'm missing?

Answers


Check the version of apache you are using. It may be that your apache is too old to support it. I think sni was supported in apache 2.2.12 and later.


Need Your Help

Passing checkbox values as JSON in Jquery

javascript jquery ajax json checkbox

I have an input form which has three text fields and a checkbox input section where the user can select more than one value. I also have an ajax request which sends a POST request to an api. I have

How to make dynamic associations in Doctrine based on dynamic variable?

php oop zend-framework doctrine-orm

Im quite new to doctrine2. I need to make a connection like this: