Apache2 certificates does not match

If your Apache2 is blocked (status inactive) because of SSL certificates’ issue, this article can be the solution you are looking for.

You can occasionally stumble in a problem of certificates mismatching, in other words you are probably using a certificate that is not related with the given private key.

It can happen especially if you are renewing your certificates manually, more over you can experience this issue when you use Certera or more generally letsencrypt certificates.

The symptoms are that the webserver is not active (inactive) and all your virtual hosts are not reachable on both 80 and 443 ports.

Furthermore the web server (apache2 in our case) is not up and running.

How to deal with that?

Simple, use the right certificates!

How can I be sure about the certificate mismatching?

Simple again 🙂

You can use this commands

openssl x509 -noout -modulus -in cert.pem | openssl md5
openssl rsa -noout -modulus -in privkey.pem | openssl md5

You will be ok when the resulting md5 string is the same for both certificates.

Useful details and references

Note that your certificate can have .crt extension rather than the .pem one.
Also the privkey.pem can have a different name with .key extension.

To check if your apache2 is working correctly (i.e. status active) you can run this command:

systemctl status apache2

To check if there is some error you can use the command

tail -f /var/log/apache2/*.log

The solution has been ispired by this very useful article on Digicert.com.

Come controllare la scadenza di un certificato SSL da console con Ubuntu

Talvolta verificare quale sia la data di scadenza di un certificato crt o pem, presente sul proprio filesystem, specie se la macchina dove si trova tale certificato, non è esposta su internet o semplicemente il certificato non è visualizzabile per mezzo di un web browser, come nel caso dei certificati SSL per i siti web.

Pertanto, entriamo subito nel vivo e vediamo come fare per ottenere l’expiration date del certificato SSL.

Leggere la data di scadenza di un certificato SSL con estensione pem o con estensione crt, eseguendo un comando direttamente da terminale su OS Linux Ubuntu.

È possibile controllare quando scade la validità di un certificato SSL (di tipo pem o di tipo crt) eseguendo un semplice comando dalla console di Ubuntu (da bash nel terminale).

Per farlo possiamo usare i comandi forniti da OpenSSL.

cat /path/to/my/cert/certificate.crt | openssl x509 -noout -enddate

Ovviamente dopo il comando “cat”, che stampa il testo del certificato, ci deve essere il path completo del certificato, sostituire quello fornito in esempio.

Si dovrebbe ottenere in uscita un testo simile a questo:

notAfter=Jul 17 08:01:33 2021 GMT

Dove è riportata la data dopo la quale il certificato viene considerato scaduto.