This guide walks you through enabling HTTPS on Apache without a domain name or public IP, using a self-signed SSL certificate. This setup is useful for local development or internal networks where a public certificate is not required.
By default, Apache serves content over HTTP (port 80), which transfers data in plaintext. This means any data exchanged between the server and the client can be intercepted. HTTPS (port 443) encrypts the connection using SSL/TLS, securing sensitive data such as login credentials.
A self-signed certificate allows HTTPS access without requiring a certificate from a Certificate Authority (CA).
Run the following command to create an SSL certificate and private key:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/selfsigned.key \
-out /etc/ssl/certs/selfsigned.crt
After execution, two files will be generated:
Apache needs the ssl module to support HTTPS. Enable it using:
sudo a2enmod ssl
Then restart Apache to apply the changes:
sudo systemctl restart apache2
sudo nano /etc/apache2/sites-available/ssl-site.conf
<VirtualHost *:443>
ServerName 192.168.85.141
SSLEngine on
SSLCertificateFile /etc/ssl/certs/selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/selfsigned.key
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now, enable the new SSL configuration and restart Apache:
sudo a2ensite ssl-site.conf
sudo systemctl restart apache2

To force all HTTP requests to be redirected to HTTPS, modify the Apache default configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Add the following line inside the <VirtualHost *:80> block:
Redirect "/" "https://192.168.85.141/"
Save and restart Apache:
sudo systemctl restart apache2
Now, all HTTP traffic will automatically be redirected to HTTPS.
To check if Apache is serving HTTPS properly, use:
sudo apachectl -S
It should list your SSL-enabled virtual host.
You can also test the SSL connection using openssl:
openssl s_client -connect localhost:443
If the connection is successful, the SSL certificate details will be displayed.
You can also try and make a packet capture and check for encrypted traffic.
