Nginx and SSL
🔒

Nginx and SSL

Published
Published May 25, 2022
 

Nginx Configuration Setup

Install Nginx

sudo apt update sudo apt install nginx

Link port with domain

Open this file in nano or vim /etc/nginx/nginx.conf
http{ server{ listen 80; server_name DOAMIN.com www.DOMAIN.com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://<IP_ADDRESS>; } } }
After updating nginx.conf apply these commandsTest nginx.conf sudo nginx -tRestart nginx service sudo systemctl restart nginx or sudo service nginx restartCheck nginx status sudo systemctl status nginx or sudo service nginx status

Issue ssl certificate from certbot

Install certbot

sudo apt-get update sudo apt-get install certbot sudo apt-get install python-certbot-nginx

Obtain the SSL/TLS Certificate

sudo certbot --nginx -d example.com -d www.example.com
It’ll handle the required modification for https in nginx.conf

Automatically Renew Let’s Encrypt Certificates

crontab -e0 12 * * * /usr/bin/certbot renew --quiet

Manually setup SSL and https configuration on nginx

http{ server{ listen 80; server_name spotcodes.in www.spotcodes.in; return 301 https://$server_name$request_uri; }
server { listen 443 ssl; server_name spotcodes.in www.spotcodes.in;
ssl_certificate /etc/letsencrypt/live/spotcodes.in/cert.pem; ssl_certificate_key /etc/letsencrypt/live/spotcodes.in/privkey.pem;
location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://3.83.202.107:2001; } } }

Test SSL certificate installation

Usefull links and credits

 
Visit on Medium