Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Apache has a certificate, but https:// does not open

Errorhttp://example.com opens but https://example.com does not

Short answer

HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in. Test from the server and from outside. If it works locally but not remotely, the block is in a firewall or a cloud security group.

  • Applies to Apache 2.4, Ubuntu 24.04, AWS EC2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the server itself whether anything listens on port 443, then request the site from the same machine. Where it stops tells you which cause applies.

    sudo ss -ltnp | grep ':443'
    curl -vk https://localhost/
  2. 2Match what you see, then jump to its fix

    1. 1apache2ctl configtest complains about an SSL directive it does not know, or nothing listens on 443.mod_ssl is not enabledFix
    2. 2Port 443 is not in the ss output, or it answers but with the wrong site.There is no virtual host on port 443, or SSLEngine is offFix
    3. 3Apache waits for a pass phrase, or the service does not come up after you added the key.Apache stops at startup because the private key is encryptedFix
    4. 4curl -vk https://localhost/ works on the server, but from outside the connection times out.The firewall or the cloud security group blocks port 443Fix

What does the error look like?

  • http://example.com opens but https://example.com does not
  • No line with :443 in the output of ss -ltnp
  • The browser times out or refuses the connection on port 443

Cause 1 of 4

mod_ssl is not enabled

1Check

List the loaded modules and look for ssl_module.

sudo apache2ctl -M | grep ssl

2Fix

Enable the module on Debian or Ubuntu with a2enmod, which creates the links in mods-enabled, then restart Apache.

sudo a2enmod ssl
sudo systemctl restart apache2

3Verify

The module is listed and the config test passes.

sudo apache2ctl -M | grep ssl
sudo apache2ctl configtest

Confirmed by manpages.ubuntu.com

Did this fix it?

Cause 2 of 4

There is no virtual host on port 443, or SSLEngine is off

1Check

Apache's SSL engine is off by default, for the main server and for each virtual host. Search the enabled sites for a 443 block.

grep -R -n -E "Listen|VirtualHost|SSLEngine|SSLCertificate" /etc/apache2/sites-enabled/ /etc/apache2/ports.conf

2Fix

Add a listener on 443 and a virtual host with SSLEngine on and both certificate paths. Apache's own documentation lists these as the minimum.

Listen 443
<VirtualHost *:443>
    ServerName www.example.com
    SSLEngine on
    SSLCertificateFile "/etc/ssl/certs/www.example.com.crt"
    SSLCertificateKeyFile "/etc/ssl/private/www.example.com.key"
</VirtualHost>

3Verify

Test the config, reload, and confirm the listener.

sudo apache2ctl configtest && sudo systemctl reload apache2
sudo ss -ltnp | grep ':443'

Confirmed by httpd.apache.org

Did this fix it?

Cause 3 of 4

Apache stops at startup because the private key is encrypted

1Check

If the key file is encrypted, mod_ssl asks for a pass phrase at startup.

head -n 1 /etc/ssl/private/www.example.com.key

2Fix

Write an unencrypted copy of the key for the server (openssl pkey writes the output unencrypted unless you ask for a cipher), or set SSLPassPhraseDialog to a program that prints the pass phrase.

sudo openssl pkey -in /etc/ssl/private/www.example.com.key -out /etc/ssl/private/www.example.com.plain.key
sudo chmod 600 /etc/ssl/private/www.example.com.plain.key

3Verify

Point SSLCertificateKeyFile at the new file, then restart Apache and confirm it is running.

sudo systemctl restart apache2 && systemctl is-active apache2

Confirmed by httpd.apache.org

Did this fix it?

Cause 4 of 4

The firewall or the cloud security group blocks port 443

1Check

On AWS, the instance's security group must allow inbound TCP 443. Security groups for a web server list both 80 and 443 as separate inbound rules.

curl -vI --max-time 10 https://YOUR_PUBLIC_IP/

2Fix

Add an inbound rule for TCP 443 (from 0.0.0.0/0, and ::/0 for IPv6 if you use it). If the server runs its own host firewall, allow 443 there too.

# Inbound rule on the instance's security group
Type: HTTPS   Protocol: TCP   Port: 443   Source: 0.0.0.0/0 (and ::/0 for IPv6)

3Verify

From your own computer, request the site.

curl -vI https://example.com/

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Run apache2ctl configtest before every reload and keep the 443 virtual host in its own file.
  • Keep keys unencrypted only on the server, with mode 600, or use a pass phrase program for encrypted ones.
  • Test from outside the network after every change to a security group.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

AWS CLI says you must specify a region

You must specify a region. You can also configure your region by running "aws configure".

The AWS CLI sends every request to one region and has none to use.

4 causes, each with a fix

Servers

EC2 Instance Connect from the browser will not open an SSH session

Host key validation failed for EC2 Instance Connect

Browser-based EC2 Instance Connect needs five things at once: a fresh host key in the AWS database, a current agent package, port 22 open to the EC2 Instance Connect prefix list, a public address with a route (or an Instance Connect Endpoint), and a browser that can reach the proxy on port 443.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.