I generated a self signed cert for my local development server, following this guide https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-18-04

I set my server IP as "Common Name" value, when asked. I did not set the firewall.

Once made all the other modifications suggested by the guide, I can reach


I have some virtual hosts that I want to protect, so I tried to use the same certificate to access my sites in https, but I'm always redirected to the apache root page.

This is my config file


<VirtualHost *:80>
    SSLEngine on
    SSLCertificateFile     /etc/ssl/certs/apache-selfsigned.crt
    SSLCertificateKeyFile  /etc/ssl/private/apache-selfsigned.key`

Where am I wrong?

1 Answer 1


You seem to be listening to port 80 instead of port 443 in your Virtual Host configuration.

The top line should be:

<VirtualHost *:443>

There might be another issue as well. You mention the following:

I have some virtual hosts that I want to protect, so I tried to use the same certificate to access my sites in https [...]

Yet, you also mention that you are accessing your sites with the server's IP address.

This approach will not work, you cannot have multiple virtual hosts listening on the same host, only one will work.

For example, consider you have the following two virtual hosts:

  • example.conf
  • kopakabana.conf

When you access your server through Apache, it will need to figure out which site it needs to serve. It cannot serve both.

Since you access your site through an IP, Apache will serve the first matched virtual host. In your case, it may be resolving to the default config file.

What you need to do is to actually assign a server name to your virtual hosts. And if you want to run them with the same certificate, you can create them as subdomains and assign them a wildcard certificate.

For example, consider the following virtual hosts:

  • example.conf

    <VirtualHost *:443>
        ServerName example.mymachine.local
        # [...]
  • kopakabana.conf

    <VirtualHost *:443>
        ServerName kopakabana.mymachine.local
        # [...]

In this case, you would create a certificate for *.mymachine.local and use it on both of them.

Next, just edit the /etc/hosts file on your own machine and append the following to it so your browser can resolve the domain properly.   example.mymachine.local   kopakabana.mymachine.local

Finally, instead of accessing, you would access https://kopakabana.mymachine.local or https://example.mymachine.local.

  • Thanks. Your solution makes sense and maybe is the right one... but unfortunately does not fit my needs. I believe that I will remove https access from my local server... it's just a development server, I can live without it. Thanks again. May 9, 2019 at 15:46

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.