KenoKivabe

Your Essential Queries

Author
Md Mojahedul Islam
07 Mar, 2023

How To Setup Lets Encrypt SSL Certificate On Ubuntu Nginx And Auto Renew


1) Install Nginx

  1. sudo apt-get update  
  2. sudo apt-get install nginx 

2) Install Certbot (the tool that will help you generate and renew SSL certificates from Let's Encrypt)

  1. sudo add-apt-repository ppa:certbot/certbot  
  2. sudo apt-get update  
  3. sudo apt-get install certbot python3-certbot-nginx 

3) Configure Nginx server block for your website. Open the Nginx configuration file for your website:

  1. sudo nano /etc/nginx/sites-available/example.com 

Replace "example.com" with your own domain name. Add the following server block:

  1. server {  
  2.     listen 80;  
  3.     server_name example.com;  
  4.     return 301 https://$server_name$request_uri;  
  5. }  
  6.   
  7. server {  
  8.     listen 443 ssl;  
  9.     server_name example.com;  
  10.   
  11.     ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;  
  12.     ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;  
  13.   
  14.     # Other Nginx configurations for your website  

4) Test the Nginx configuration file

  1. sudo nginx -t 

5) If there are no errors, reload Nginx to apply the changes

  1. sudo systemctl reload nginx 

6) Generate the SSL certificate with Certbot

  1. sudo certbot --nginx -d example.com -d www.example.com 

7) Certbot will automatically configure Nginx to use the SSL certificate and renew it when it's close to expiration.

That's it! Your website is now secured with Let's Encrypt SSL and will automatically renew the SSL certificate when needed.

Share: