To generate self signed SSL certificate, run
openssl genrsa -out DOMAIN_NAME_HERE.key 2048
openssl req -new -x509 -key DOMAIN_NAME_HERE.key -out DOMAIN_NAME_HERE.crt -days 3650 -subj /CN=DOMAIN_NAME_HERE
Or
openssl req -newkey rsa:2048 -nodes -keyout DOMAIN_NAME_HERE.key -x509 -days 3650 -out DOMAIN_NAME_HERE.crt
Add Self Signed SSL to Apache Virtual Host
Let’s say your Apache virtual host entry is
<VirtualHost *:80>
ServerName serverok.in
ServerAlias www.serverok.in
ServerAdmin [email protected]
DocumentRoot /home/serverok.in/public_html
<Directory "/home/serverok.in/public_html">
Options All
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Create a new VirtualHost entry based on this, say yourdomain-ssl.conf, in this new file
Find
<VirtualHost *:80>
Replace with
<VirtualHost *:443>
Find line starting with
DocumentRoot
Add Below
SSLEngine on
SSLCertificateFile /etc/ssl/yourdomain.crt
SSLCertificateKeyFile /etc/ssl/yourdomain.key
Now restart Apache
systemctl restart apache2
How to access the website using a Self-signed SSL certificate
See SSL