DEV Community

Juliana Dias
Juliana Dias

Posted on

7

ChatGPT: basic example of an Nginx configuration file using an auto-signed SSL certificate

This article was created by ChatGPT

Here is a basic example of an Nginx configuration file using an auto-signed SSL certificate:

Copy code
server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

    location / {
        # your application code here
    }
}
Enter fullscreen mode Exit fullscreen mode

Here are the steps to generate the auto-signed SSL certificate and key files:

Generate the SSL certificate and key files using OpenSSL:

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/ssl/private/nginx-selfsigned.key \
  -out /etc/ssl/certs/nginx-selfsigned.crt
Enter fullscreen mode Exit fullscreen mode

This command will prompt you for some information to include in the certificate, such as the Common Name (CN) which should be set to your domain name (e.g. example.com).

Verify that the certificate and key files were generated:

$ ls -l /etc/ssl/private/nginx-selfsigned.key /etc/ssl/certs/nginx-selfsigned.crt
Enter fullscreen mode Exit fullscreen mode

You should see output similar to:

-rw-r--r-- 1 root root 1091 Feb 24 15:44 /etc/ssl/certs/nginx-selfsigned.crt
-rw-r--r-- 1 root root 1675 Feb 24 15:44 /etc/ssl/private/nginx-selfsigned.key
Enter fullscreen mode Exit fullscreen mode

Copy the configuration file above into your Nginx server block, replacing the example.com server name with your own domain name.

Reload the Nginx configuration:

$ sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

That's it! Your Nginx server should now be configured to use the auto-signed SSL certificate.

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay