Apache has a certificate, but https:// does not open
http://example.com opens but https://example.com does notShort 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.
Fix it fast
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/2Match what you see, then jump to its fix
- 1
apache2ctl configtest complains about an SSL directive it does not know, or nothing listens on 443.mod_ssl is not enabledFix - 2
Port 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
Apache 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
curl -vk https://localhost/ works on the server, but from outside the connection times out.The firewall or the cloud security group blocks port 443Fix
- 1
What does the error look like?
http://example.com opens but https://example.com does notNo line with :443 in the output of ss -ltnpThe 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 ssl2Fix
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 apache23Verify
The module is listed and the config test passes.
sudo apache2ctl -M | grep ssl
sudo apache2ctl configtestConfirmed by manpages.ubuntu.com
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.conf2Fix
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
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.key2Fix
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.key3Verify
Point SSLCertificateKeyFile at the new file, then restart Apache and confirm it is running.
sudo systemctl restart apache2 && systemctl is-active apache2Confirmed by httpd.apache.org
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
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:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
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 fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
git clone from CodeCommit over HTTPS returns 403
aws codecommit credential-helper $@ get: aws: command not found
A 403 from CodeCommit over HTTPS usually means Git sent the wrong credentials, not none.
5 causes, each with a fixServers
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 fixServers
EC2 instance shows 'Instance reachability check failed' and will not answer
Out of memory: kill process
A failed instance reachability check means the operating system inside the instance is not responding, so the problem is yours to fix, not AWS hardware.
4 causes, each with a fixServers
ssh to an EC2 instance hangs and ends in Connection timed out
Network error: Connection timed out
A timeout means your packets never got an answer, so this is a network path problem, not a key problem.
4 causes, each with a fix