I'm trying to set up a self-signed SSL certificate between my own VPS and Cloudflare (next to Full SSL). I'm using the following VirtualHosts for this:

<VirtualHost *:80>
        ServerName domain.com
        Redirect permanent / https://www.domain.com/

<VirtualHost *:443>
        ServerName www.domain.com
        DocumentRoot /var/www/public/www

        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key

But whenever I try to access domain.com it returns a 403 Forbidden and I get the following error in my apache2 logs:

[Fri Jan 30 00:19:23 2015] [error] [client (ip)] Directory index forbidden by Options directive: /var/www/public/

Meaning it tries to access the default DocumentRoot as set in apache2.conf:

ServerAdmin server@domain.com
DocumentRoot /var/www/public

Note that it does work when I change the port of the second VirtualHost to 80 and comment the 3 lines about SSL.

So my question is: why is not using the DocumentRoot that I specified in the VirtualHost (*:433)?


When I pause Cloudflare and go to https://www.domain.com I can access it (of course with a warning because the certificate is self-signed). So maybe it has something to do with Cloudflare?

  • Where is the rest of your configuration? – Michael Hampton Jan 29 '15 at 23:39
  • What part/files do you need? Everything else is pretty much default. – Cas Cornelissen Jan 29 '15 at 23:43
  • There's probably a <Directory /var/www/public> (or for /var/www) somewhere, what's it have? Are there .htaccess files in any of these directories? – Shane Madden Jan 30 '15 at 0:05

My guess is that you have to enable NameVirtualHost for the SSL port.
It can be done by editing the file /etc/apache2/ports.conf.
There you can see the configuration for port 80:

NameVirtualHost *:80
Listen 80

You can also see the IFmodule mod_ssl.c tags.
By default there should only be "Listen 443" inside the tags and you just have to add "NameVirtualHost *:443" above the "Listen 443" line. I believe this should fix your issue.

Apparently I don't have the reputation to post images, so here you go: http://i.imgur.com/vGCEAGb.png

EDIT: Don't forget to restart Apache.

| improve this answer | |
  • I'm now getting the warning NameVirtualHost *:433 has no VirtualHosts while I did change the second VirtualHost to 433. – Cas Cornelissen Jan 30 '15 at 10:03
  • Ignore my previous comment. I mistyped 443 as 433. – Cas Cornelissen Jan 30 '15 at 10:25
  • This does seem to do it when I pause Cloudflare. As soon as I enable Cloudflare again I run into the same 403 Forbidden error... I also contact Cloudflare with the same question and a link to this thread. – Cas Cornelissen Jan 30 '15 at 11:08
  • If it works without Cloudflare it could be an issue with Cloudflare's caching. It might be showing you an cached version of your page from when it didn't work. (It's been a while since I've used Cloudflare, but sounds like a caching issue) – Niklas Lindgren Jan 30 '15 at 13:50
  • 1
    I believe there is a flush cache option somewhere in Cloudflare's control panel, I'd try that. – Niklas Lindgren Jan 30 '15 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.