10

Okay, so I've had no experience with SSL/HTTPS ever before, I've only ever dealt with standard HTTP. Recently I've started work on a site which will need SSL. So of course, I've gone out and researched how to and got started. I've got to the stage of installing the SSL certificate successfully - the green padlock appears and the server responds to HTTPS requests on port 443. The issue I have is that no matter what I do I cant get any pages to appear using HTTPS/SSL, however they appeared fine on port 80/HTTP (until I redirect HTTP to HTTPS that is).

Put simply I can access the HTTPS site absolutely fine, however my pages are not being sent, rather a 404 is sent for every request.


/etc/apache2/sites-available/[name].conf

<VirtualHost *:80>
    ServerName [serverName]

    RewriteEngine On

    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
</VirtualHost>

<VirtualHost *:443>
    ServerName [serverName]
    ServerAdmin [email]
    DocumentRoot [docRoot]

    # I know the following SSL cert stuff is correct

    SSLEngine On
    SSLCertificateFile [...]/[domain].crt
    SSLCertificateKeyFile [...]/[certificate].key
    SSLCertificateChainFile [...]/[theotherone].crt

    ErrorLog ${APACHE_LOG_DIR}/[custom]_error.log
        CustomLog ${APACHE_LOG_DIR}/[custom]_access.log combined

        <Directory "[docRoot]">

                Options Indexes FollowSymLinks MultiViews

        AllowOverride All
        Order allow,deny
        allow from all

        </Directory>

</VirtualHost>

I'm not sure if there is anything else you might want to look at, or any other details, but if there is let me know.

EDIT:

After some searching around in the config files I have established that for whatever reason, when connecting to HTTPS, the server is using the document root in the default configuration (/var/www/) however this default configuration is not enabled with a2ensite. I can't seem to figure where the configuration that is causing this is located

  • Your `Rewrite` directives look like you are trying to run Apache behind a badly configured reverse proxy. If your Apache is serving the domain directly without any proxying, you should just drop all of the `Rewrite` directives and replace them with a single `Redirect`. And configure separate logfiles for each `VirtualHost` such that you can see exactly which `VirtualHost` process each request. – kasperd Dec 11 '16 at 22:45
  • As for the Rewrites, I was only using them to get a temporary refirect (I wasn't 100% sure at that stage), I have now learned that Redirect is perfectly capable of that (yeah, bad that I didn't know that). Regarding the separate log files, I have since done that. I also have figured out what the issue was and will update to reflect that. – Michael Longhurst Dec 12 '16 at 01:13

3 Answers3

11

Is it absolutely necessary to redirect all http requests to https? Cause it seems that's what you're trying to do here.

I suggest you start by removing the following lines from your conf:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]

I suspect the syntax may be wrong there. Then try connecting again on each http:// and https:// protocols.

Ivan
  • 893
  • 2
  • 9
  • 23
11

I can't exactly remember how I figured it out, but I stumbled across something somewhere that suggested to put:

<VirtualHost _default_:443>

Instead of:

<VirtualHost *:443>

Since replacing that, my SSL has been working perfectly.

10

Try editing your file to look something like this:

This is a very basic conf, if this works add your redirects if still needed.

If this does not work please show your ssl.conf

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
         <Directory "[docRoot]">
        AllowOverride All
        </Directory>
        DocumentRoot [docRoot]
        ServerName [serverName]
</VirtualHost>

<VirtualHost *:443>
        SSLEngine on
       SSLCertificateFile [...]/[domain].crt
       SSLCertificateKeyFile [...]/[certificate].key
       SSLCertificateChainFile [...]/[theotherone].crt
         <Directory "[docRoot]">
        AllowOverride All
        </Directory>
        DocumentRoot [docRoot]
        ServerName [serverName]
</VirtualHost>
Anthony Fornito
  • 9,526
  • 1
  • 33
  • 122