I purchased a certificate that is valid for both www.example.com and example.com. My server is working only with "www.example.com" (ssl is working fine) but it is not showing anything at all when I type "example.com" on the browser. Here is my apache file config which basicly is the same virtualHost twice but with different ServerName
Define APACHE_LOG_DIR /var/log/apache2
Define SSLCERTIFICATE /etc/apache2/ssl/mycertificate.crt
Define SSLKEY /etc/apache2/ssl/mykey.key
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName www.example.com
DocumentRoot /var/www/site2/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile ${SSLCERTIFICATE}
SSLCertificateKeyFile ${SSLKEY}
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/var/www/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
# Same documetn root for example.com (without www)
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName example.com
DocumentRoot /var/www/site2/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile ${SSLCERTIFICATE}
SSLCertificateKeyFile ${SSLKEY}
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/var/www/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
Aditional Information:
- my site is hosted in a virtual machine in Azure (Ubuntu 14.04 LTS)
- the domain name is from goDaddy
- there is another configuration file for http (port 80)
Best Answer
Since your certificate is valid for both
example.com
andwww.example.com
, and both domains are configured to use the same directories, there is no reason that I can see for having them as separate VirtualHosts. I would remove the second VirtualHost and change the first one to look like this: