Configure SSL/TLS with Apache on Ubuntu 26.04
To turn on HTTPS in Apache2 on an Ubuntu server, enable the ssl module, point the default-ssl site at a certificate and key, enable that site, and restart Apache. You can do all of it from a Windows 11 PC over SSH (a secure way to log in to another computer and run commands). This guide uses a self-signed certificate, which suits a lab or internal server.
To turn on HTTPS in Apache2 on Ubuntu 26.04, run sudo a2enmod ssl, point the default-ssl site at your certificate and key in /etc/apache2/sites-available/default-ssl.conf, then run sudo a2ensite default-ssl. Test with sudo apache2ctl configtest and restart Apache with sudo systemctl restart apache2. This guide uses a self-signed certificate, which suits labs and internal servers.
Before you start
You need an Ubuntu Server with Apache2 installed, a user account that can run sudo (administrator rights on Linux), and network access from your Windows PC to the server. Each command below that starts with sudo needs administrator rights.
The examples use 192.0.2.10 as the server address, USERNAME as your account name, and www.example.com as the site name. Replace them with your own values.
Connect to the server from 🪟 Windows 11
Windows 11 includes an OpenSSH client (a built-in tool for remote command-line sessions), so you do not need extra software.
- Right-click the Start button and choose Terminal.
- Type the SSH command below and press Enter.Code
ssh USERNAME@192.0.2.10
- Type
yesif Windows asks you to trust the server’s fingerprint (a short code that identifies the server), then enter your password. You should now see the Ubuntu command prompt.
Install Apache2 if it is missing
Skip this section if Apache2 already runs on the server.
- Update the package list and install Apache2. This step needs administrator rights, so start each command with
sudo.Bash / Shellsudo apt update
sudo apt install apache2 - Check that the service is active.Code
systemctl status apache2
- Look for active (running) in the output, then press Q to leave the status view.
Create a self-signed certificate
A self-signed certificate encrypts traffic, but no public authority vouches for it. Browsers show a warning until you trust it. If the server faces the internet, use a certificate from a public authority such as Let’s Encrypt instead.
- Create the certificate and its private key (the secret file that proves the certificate is yours) in one command. This step needs administrator rights, so start the command with
sudo. The-addextflag adds the site name that modern browsers check, which is called the Subject Alternative Name.Bash / Shellsudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/example.key -out /etc/ssl/certs/example.crt -addext "subjectAltName=DNS:www.example.com"
- Answer the prompts for country, organization and so on. For Common Name (the site name the certificate is issued for), enter the name people will use to reach the site, such as
www.example.com. - Confirm both files exist.Bash / Shell
ls -l /etc/ssl/certs/example.crt /etc/ssl/private/example.key
.key file private.Anyone who has it can impersonate your server.
Point the SSL site at your certificate
Ubuntu ships a ready-made HTTPS site definition called default-ssl. You only need to change the certificate paths in it.
- Open the file in the nano text editor (requires
sudo).Bash / Shellsudo nano /etc/apache2/sites-available/default-ssl.conf
- Find the line that starts with
SSLCertificateFileand change it to the value shown below.CodeSSLCertificateFile /etc/ssl/certs/example.crt
- Find the line that starts with
SSLCertificateKeyFileand change it to the value shown below.CodeSSLCertificateKeyFile /etc/ssl/private/example.key
- Add a
ServerNameline just below theServerAdminline.CodeServerName www.example.com
- Press Ctrl + O, then Enter to save. Press Ctrl + X to exit.
Enable SSL and restart Apache
These commands switch on the SSL module and the HTTPS site, then check your configuration before applying it.
- Enable the SSL module (requires
sudo).Bash / Shellsudo a2enmod ssl
- Enable the HTTPS site.Bash / Shell
sudo a2ensite default-ssl
- Test the configuration for mistakes.Bash / Shell
sudo apache2ctl configtest
- Look for Syntax OK. A warning about the server's fully qualified domain name (the complete host address, such as server.example.com) is harmless, and the
ServerNamesetting from the earlier step usually clears it. If you see an error instead, fix the file it names before going on. - Restart Apache.Bash / Shell
sudo systemctl restart apache2
Allow HTTPS through the firewall
Skip this section if UFW (Ubuntu's firewall tool) is not active on the server. Check with sudo ufw status.
- Allow TCP port 443, the standard HTTPS port (requires
sudo).Bash / Shellsudo ufw allow 443/tcp
- Run
sudo ufw statusand confirm that 443/tcp shows as ALLOW.
Test the HTTPS connection from Windows
- Open a browser on your PC and go to
https://www.example.com. If the name does not resolve, usehttps://192.0.2.10. A name that does not match the certificate triggers an extra warning. - Expect a security warning for a self-signed certificate. Select Advanced, then choose to continue to the site. You should see the Apache default page over HTTPS.
- For a quick check without a browser, open Terminal and run:Code
curl.exe -k -I https://192.0.2.10
- Look for HTTP/1.1 200 OK in the reply. The
-kflag tells curl, a command-line tool that fetches web pages, to accept the self-signed certificate. Use it only for testing.
Trust the certificate on your Windows PC (optional)
Trust only a certificate you created yourself. A trusted root can vouch for any site its certificates cover, so trusting someone else's certificate is a security risk.
- Copy the certificate to your PC. In Terminal, run:Code
scp USERNAME@192.0.2.10:/etc/ssl/certs/example.crt .
- Double-click example.crt in the folder where you saved it, then select Install Certificate.
- Choose Current User and select Next.
- Select Place all certificates in the following store, then Browse.
- Choose Trusted Root Certification Authorities and select OK.
- Select Next, then Finish. Confirm the security prompt with Yes.
- Restart your browser and reload the page. The warning should be gone, provided the address matches the name in the certificate.
To undo this, press Windows + R, type certmgr.msc, press Enter, open Trusted Root Certification Authorities Certificates, right-click the certificate and choose Delete.
Redirect HTTP visitors to HTTPS (optional)
- Open the default HTTP site file (requires
sudo).Bash / Shellsudo nano /etc/apache2/sites-available/000-default.conf
- Add this line inside the
<VirtualHost *:80>block:CodeRedirect permanent / https://www.example.com/
- Save the file and exit nano.
- Reload Apache.Bash / Shell
sudo systemctl reload apache2
- Type
http://www.example.comin your browser's address bar. The browser should then jump to the HTTPS address.
If the page does not load
- If the page does not load, check that Apache is listening on port 443.Bash / Shell
sudo ss -tlnp | grep 443
- Then check the newest lines in the Apache error log.Bash / Shell
sudo tail -n 30 /var/log/apache2/error.log
- If the log mentions a certificate or key file, recheck the two paths in
default-ssl.conffor typos.
What to do next
To undo the change, run sudo a2dissite default-ssl followed by sudo systemctl reload apache2. If the server is public, replace the self-signed certificate with a Let's Encrypt certificate so visitors see no warning. Then update the two SSLCertificate lines to point at the new files. Renewing or swapping a certificate later needs only a reload of Apache.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!