Linux - Generate Self SSL (Localhost HTTPS/SSL)

I wrote these tutorials for myself in future when I forget for the next steps.
Search for a command to run...

I wrote these tutorials for myself in future when I forget for the next steps.
No comments yet. Be the first to comment.
When you provision an Ubuntu instance on Oracle Cloud, you'll notice something different from standard Ubuntu installations: the system uses iptables instead of ufw for firewall management. This disti

When developing web applications locally, HTTPS is often overlooked. Yet, modern browsers and APIs increasingly require secure connections—even in development. That’s where mkcert comes in: a simple t

Testing the checkout success page in Magento 2 can be frustrating. By default, once an order is placed, Magento clears the quote session, meaning you can’t simply refresh or revisit the success page without going through the entire checkout process a...

Magento Commerce (EE) offers powerful features, but for many teams, Open Source (CE) is leaner, lighter, and more sustainable. If you're migrating from EE to CE, the Opengento downgrade tool provides a clean, scriptable way to remove proprietary modu...

If you’ve ever checked your Apache error logs and seen something like this: Code [core:error] (13)Permission denied: access to /robots.txt denied (filesystem path '/home/username/sites') because search permissions are missing on a component of the pa...

In this article, I'll walk you through the steps to generate a self-signed SSL certificate for localhost on a Linux system. We'll use mkcert, a simple tool for making locally trusted development certificates. Also just to highlight it, I’m using arm base processor, so I use arm64 version.
First, we need to download the mkcert binary and make it executable:
sh
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/arm64"
chmod +x mkcert-v*-linux-amd64
sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert
Next, we'll use mkcert to generate the SSL certificate and key for localhost:
sh
mkcert -key-file testing-key.pem -cert-file testing-cert.pem testing-dev.fiko.me
This command will create localhost-key.pem and localhost-cert.pem files.
Now, let's configure Nginx to use the generated SSL certificate. Add the following configuration to your Nginx server block:
nginx
server {
listen 445 ssl;
server_name testing-dev.fiko.me;
set $MAGE_ROOT /home/fiko/sites/testing;
set $MAGE_MODE developer; # or production, depending on your environment
ssl_certificate /home/fiko/downloads/testing-cert.pem;
ssl_certificate_key /home/fiko/downloads/testing-key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
include /home/fiko/sites/testing/nginx.conf.sample;
error_page 404 /errors/404.php;
error_page 500 502 503 504 /errors/503.php;
access_log /var/log/nginx/testing_ssl.access.log;
error_log /var/log/nginx/testing_ssl.error.log;
}
Make sure the paths to the SSL certificate and key files are correct.
Finally, restart Nginx to apply the new configuration:
sh
sudo systemctl restart nginx
Your Nginx server should now be serving the site over HTTPS using the self-signed certificate.
By following these steps, you can generate a self-signed SSL certificate for localhost and configure Nginx to use it. This setup is great for development environments where you need HTTPS but don't want to obtain a certificate from a Certificate Authority.
Happy coding! 😊