Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Configure Apache With Self-Signed TLS/SSL Certificate on Ubuntu 16.04

Rumi, February 10, 2019

Step 1: Generating the certificate

First, let’s create a place to store the file.

mkdir ~/certificates
cd ~/certificates

Generate CSR and private key.

openssl req -x509 -newkey rsa:4096 -keyout apache.key -out apache.crt -days 365 -nodes

It will ask for information for the certificate request. Complete with the appropriate information.

Country Name (2 letter code) [AU]: US
State or Province Name (full name) [Some-State]: FL
Locality Name (eg, city) []: Miami
Organization Name (eg, company) [My Company]: My Company
Organizational Unit Name (eg, section) []:

Common name should be your domain name or the server’s IP address. Also, fill in your email.

Common Name (e.g. server FQDN or YOUR name) []: 203.0.113.122
Email Address []:webmaster@example.com

Now, move the certificate to Apache configuration folder.

mkdir /etc/apache2/ssl
mv ~/certificates/* /etc/apache2/ssl/.

The certificate is ready! Next, we will prepare Apache to work with the certificate.

Step 2: Firewall configuration

We have to make sure TCP port 443 is open. This port is used in SSL connections instead of port 80. In this tutorial, we will be using UFW.
Make sure UFW is enabled.

sudo ufw enable

Now allow the predefined Apache settings for the firewall.

sudo ufw allow 'Apache Full'

By typing “sudo ufw status”, you can see a list of the current rules. Your configuration should resemble this:

To Action From
-- ------ ----
Apache Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

You should also allow OpenSSH here for future connections.

sudo ufw allow 'OpenSSH'

Step 3: Apache virtual host configuration

Navigate to the default Apache site config directory.

sudo nano /etc/apache2/sites-available/default-ssl.conf

This file tells the server where to look for the SSL certificate. With the comments removed, it should look like the following config.

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

</VirtualHost>
</IfModule>

Edit this line:

ServerAdmin email@example.net

Add this right below the ServerAdmin line:

ServerName ADD_YOUR_IP_OR_DOMAIN_NAME_HERE

Now, edit these lines with our certificate location:

SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

Our final file should resemble this:

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin email@example.net
ServerName 203.0.113.122

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

</VirtualHost>
</IfModule>

Save and close the file.

Step 4: Enabling Apache SSL module

Enable the SSL module by typing:

sudo a2enmod ssl

Now enable the site we have just edited:

sudo a2ensite default-ssl.conf

Restart Apache:

sudo service apache2 restart

Let’s access the new secure website! Open it in your browser (make sure you type https://).

https://YOUR_SERVER_IP

Your browser will warn you that the certificate is invalid, as we expected. This happens because the certificate is not signed. Follow the steps offered by your browser to proceed to your site.

Step 5: Redirect all HTTP traffic to HTTPS (Optional)

Open the Apache default virtual host file:

nano /etc/apache2/sites-available/000-default.conf

Add this line inside the <VirtualHost *:80> tag:

Redirect / https://YOUR_SERVER_IP_OR_DOMAIN/

Reload Apache configuration:

sudo service apache2 reload

All website traffic will now automatically redirect to HTTPS.

Src: https://www.vultr.com/docs/configure-apache-with-select-signed-tls-ssl-certificate-on-ubuntu-16-04

Administrations Collected Articles Configurations (Linux) SSLUbuntuUbuntu 16.04

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx openvpn pfsense php Postfix Proxmox RDP Softether SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin Windows 10 XCP-NG zimbra

Topics

Recent Posts

  • Youtube MP3 Downloader Script using AI February 14, 2026
  • Install Softether VPN and create a Destination NAT (D-NAT) Rule to access the private Client VPN Node on a Debian 12 OS February 14, 2026
  • Deploying Pulse Monitoring for Proxmox Cluster Ecosystem February 13, 2026
  • Technitium DNS Web UI Configuration for Primary-Secondary Name Servers February 12, 2026
  • Technitium DNS with Primary-Slave Installation on Debian February 12, 2026
  • Install Docker and Docker Compose in Debian 12 February 5, 2026
  • Install GUI on Debian 12 using CLI February 4, 2026
  • Configuring Multiple PHP Versions on Virtualmin January 30, 2026
  • Deploy a Container TIG (Telegraf, InfluxDB and Grafana) Stack January 24, 2026
  • Resetting password of another Linux by mounting disk December 15, 2025

Archives

Top Posts & Pages

  • Youtube MP3 Downloader Script using AI
©2026 Bots! | WordPress Theme by SuperbThemes