How To Secure Nginx with Let's Encrypt on Ubuntu 16.04
How To Secure Nginx with Let's Encrypt on Ubuntu 16.04
Introduction
In this tutorial, we will show you how to secure your Nginx web server using Let's Encrypt SSL certificates on Ubuntu 16.04.
Prerequisites
Before you begin, you should have the following:
- A Ubuntu 16.04 server
- Nginx web server installed and running
- A registered domain name pointed to your server IP address
- A non-root user with sudo privileges
Step 1: Install Certbot
Certbot is a free, automated tool for obtaining SSL/TLS certificates from Let's Encrypt. To install Certbot, run the following commands:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
Step 2: Obtain SSL/TLS Certificate
Once Certbot is installed, you can obtain an SSL/TLS certificate for your domain by running the following command:
sudo certbot --nginx -d example.com -d www.example.com
Replace example.com and www.example.com with your domain names.
Step 3: Test SSL/TLS Certificate Renewal
Let's Encrypt SSL/TLS certificates are valid for 90 days. To ensure that your certificate is automatically renewed before it expires, run the following command:
sudo certbot renew --dry-run
Step 4: Update Nginx Configuration
Once you have obtained your SSL/TLS certificate, you need to update your Nginx configuration to use it. Open the Nginx configuration file for your site:
sudo nano /etc/nginx/sites-available/example.com
Find the listen directive for port 80 and replace it with the following:
listen 80;
return 301 https://$host$request_uri;
Find the listen directive for port 443 and replace it with the following:
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
Save and close the file.
Комментарии
Отправить комментарий