How to Issue an SSL Certificate Using Nginx and Certbot on Linux
Securing your website with HTTPS is essential for protecting user data and improving SEO rankings. This guide walks you through the process of issuing a free SSL certificate using Nginx and Certbot on a Linux server.
Prerequisites
Before you begin, ensure the following:
- You have a Linux server with
sudo
privileges. - Nginx is installed and running.
- Your domain name is pointed to your server’s IP address.
- The
snapd
package manager is installed (required for Certbot).
Step 1: Install Certbot
Certbot is a free, open-source tool for obtaining and renewing SSL certificates. Install it using the following commands:
sudo snap install core; sudo snap refresh coresudo snap install --classic certbotsudo ln -s /snap/bin/certbot /usr/bin/certbot
Step 2: Configure Nginx
Ensure your Nginx configuration is set up for your domain. For example:
server { listen 80; server_name example.com www.example.com;
root /var/www/example.com; index index.html;
location / { try_files $uri $uri/ =404; }}
Save the configuration file (e.g., /etc/nginx/sites-available/example.com
) and test it:
sudo nginx -t
Reload Nginx to apply changes:
sudo systemctl reload nginx
Step 3: Obtain an SSL Certificate
Run Certbot to automatically configure SSL for your domain:
sudo certbot --nginx -d example.com -d www.example.com
Follow the prompts to complete the process. Certbot will:
- Obtain the SSL certificate.
- Update your Nginx configuration to use HTTPS.
Step 4: Verify HTTPS
After Certbot completes, verify that your site is accessible via HTTPS by visiting:
https://example.com
Step 5: Set Up Automatic Renewal
Certbot automatically installs a cron job to renew certificates. Test the renewal process with:
sudo certbot renew --dry-run
If no errors occur, your certificates will renew automatically.
Conclusion
Congratulations! Your website is now secured with HTTPS using Nginx and Certbot. Regularly monitor your server and ensure your certificates are renewed to maintain security. For more advanced configurations, refer to the Certbot documentation.