How to setup https for local development using NGINX server

Satish Mali
2 min readApr 23, 2023

TLS/SSL transport layer security/secure sockets layer are web protocols used to protect and encrypt traffic over computer network between client and server.

In this guide, you will learn, How to set up ad self-signed SSL certificate for NGINX web server on an ubuntu server.

Check openssl version
openssl version

Create storage folder for certification
mkdir -p /etc/certs/test.com

Create TLS/SSL certificate inside /etc/certs/test.com

sudo openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out test.com.crt -keyout test.com.key

openssl: This is command line tool for creating and managing OpenSSL certificates, keys and other files.
-newkey rsa:4096: To generate new certificate and new key at the same time. rsa:4096 tells to make an RSA key that is 406 bit long.
-x509:
This command tell that we want to make self-signed certificate.
-days 365:
Validity of the certificate. we set here for one year.
-nodes:
Skip option for passphrase.
-out:
This Opnessl command tells to where to place the certificate that we are creating.
-keyout:
Where to place generated private key that we are creating.

Configure the NGINX configuration file

Create as test.com.conf file inside /etc/nginx/sites-available with below content.

server {
listen 443 ssl;

ssl_certificate /etc/certs/test.com/test.com.crt;
ssl_certificate_key /etc/certs/test.com/test.com.key;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
ssl_protocols TLSv1.1 TLSv1.2;

server_name test.com;

root /var/www/test.com;
index index.html;

location / {
try_files $uri $uri/ =404;
}
}

Create symbolic link inside /etc/nginx/sites-enabled using below command
cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/test.com.conf .

Test NGINX configuration
sudo nginx -t

Restart NGINX server
sudo systemctl restart nginx

Check NGINX server status
sudo systemctl status nginx

Now, you can run local website using https in given example you can verify using https://test.com

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Satish Mali
Satish Mali

Responses (1)

Write a response