1

I have installed an SSL certificate on my Ubuntu EC2 instance and I need one of the websites hosted on this instance to be accessible via https.

I have several websites hosted all on the same IP through Virtual Hosts. However, I only need one website to be accessible via https.

I am sure about the following:

  • SSL certificate is properly installed
  • Port 443 is open on EC2

I am sure about these because when I tried the following Virtual Host configuration in the /etc/apache2/sites-enabled/mysslsite I could access the site via https. The problem was that all the other websites went down because they also required to be accessed ONLY through https. The following is the virtual host configuration file:

<VirtualHost *>

    ServerAdmin [email protected]

        DocumentRoot    /var/www/mysslwebsite
        ServerName  www.mysslwebsite.com
        ServerAlias     mysslwebsite.com
        <Directory  /var/www/mysslwebsite>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
        </Directory>

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>

    SSLEngine on
    SSLCertificateFile    /etc/ssl/apache2/mycertificate.com.crt
    SSLCertificateKeyFile /etc/ssl/apache2/mycertificate.key

    ErrorLog /var/log/apache2/error.log
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

</VirtualHost>

With this configuration, although it is located in this specific mysslwebsite virtual host config, all the other websites won't load through standard http and show the following message when accessed through http:

Bad Request

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
Hint: https://www.myothersite.com/

Anyone knows how I can fix this?

Thank you

-------EDIT-------

I tried the following virtual hosts:

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>

    ServerAdmin [email protected]

        DocumentRoot    /var/www/mysslsite
        ServerName  www.mysslsiste.com
        ServerAlias     mysslsite.com
        <Directory  /var/www/mysslsite>

            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
        </Directory>

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>

    ErrorLog /var/log/apache2/error.log
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

</VirtualHost>

<VirtualHost *:443>
        ServerAdmin [email protected]

        DocumentRoot    /var/www/mysslsist
        ServerName  www.mysslsist.com
        ServerAlias     mysslsist.com
        <Directory  /var/www/mysslsist>

            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
        </Directory>

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>

    ErrorLog /var/log/apache2/error.log
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

    SSLEngine on
    SSLCertificateFile    /etc/ssl/apache2/certificate.com.crt
    SSLCertificateKeyFile /etc/ssl/apache2/certificate.key

</VirtualHost>

#Another virtual host with another site
<VirtualHost *>

    ServerAdmin [email protected]

        DocumentRoot    /var/www/myothersite
        ServerName  www.myothersite.com
        ServerAlias     myothersite.com
        <Directory  /var/www/myothersite>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all
        </Directory>

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>

    ErrorLog /var/log/apache2/error.log
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

</VirtualHost>

However, I could not access the website via SSL. I could access it via http though.

Apache showed the following warnings when restarting:

NameVirtualHost *:443 has no VirtualHosts NameVirtualHost *:80 has no VirtualHosts

This is confusing as port 80 has about 10 Virtual Hosts.

1 Answer 1

4

It looks to me that you are not specifying a 443 port or a 80 port for the virtual host. So everything is heading towards the virtual host which is configured for SSL. So http traffic is not being accepted as it is configured to only accept SSL. Try this

NameVirtualHost *:80

<VirtualHost *:80>
   ServerName blah
   DocumentRoot /var/www/html/

</VirtualHost>


<VirtualHost *:443>

 ...
 - your config here -
 ...

</VirtualHost>

You could even do a redirect for the virtual host running on port 80. Maybe something like this:

Redirect permanent / https://<URL>
2
  • First of all thanks for the reply. I tried this but could not access it via SSL. Please check my edit for more information on the configuration.
    – seedg
    Dec 20, 2012 at 12:57
  • Ok i see what you did as I managed to solve it. Every other virtual host was with the notation <VirtualHost *> and I had NameVirtualHost * at the beginning. This had to be changed with the 2 you mentioned all all others virtual hosts had to be changed to *:80 instead of just *
    – seedg
    Dec 20, 2012 at 15:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .