DEV Community

Cover image for The Beginner’s Guide to Self-Signed Certificates in Nginx
Rijul Rajesh
Rijul Rajesh

Posted on

The Beginner’s Guide to Self-Signed Certificates in Nginx

In this article, I will be giving you an idea of certificates when you host your site.

Let's start with a basic idea on certificates?

What is a certificate?

A certificate is like a digital ID card for your server.

Browsers trust a site only if it's ID card is signed by someone they trust.

We call these the Certificate Authority (CA)

Examples of Certificate Authority

To make this more familiar, let's see some examples of certificate authority.

  • DigiCert
  • Let's Encrypt
  • GoDaddy
  • Google Trust Services

What is a self signed certificate?

A self signed certificate is when you sign your own certificate.

When this happens, browsers will give a "Not secure" warning, Since the signing is not done by a certificate authority.

When do we use self signed certificates?

  • It is perfect for
    • Local development
    • Internal tools
    • Testing staging environments
    • Prototyping SSL setups before buying real certificates
  • It is not good for
    • Any public website
    • Anything that real users will access
    • Anything requiring browser trust.

How can you create a self-signed certificate

You can create a self-signed certificate using openssl

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
Enter fullscreen mode Exit fullscreen mode

Using the self-signed certificate in nginx

server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    server_name localhost;
    localhost / {
        root /var/www/html
    }
}
Enter fullscreen mode Exit fullscreen mode

Wrapping up

So, now you have added the self-signed certificate and learned what it means.

If you are a developer who is figuring out new things like this, and often struggled with repetitive tasks, obscure commands, or debugging headaches, this platform is here to make your life easier. It’s free, open-source, and built with developers in mind.

👉 Explore the tools: FreeDevTools

👉 Star the repo: freedevtools

Top comments (0)