Setup SSL in Nginx on Ubuntu
Setting Up SSL for Nginx on Ubuntu with Certbot
This guide will help you set up SSL for your Nginx server on Ubuntu using Certbot. We will use a subdomain from GoDaddy, and the steps include installing Certbot, configuring Nginx, and generating an SSL certificate.
1. Install Certbot and the Nginx Plugin
First, install Certbot and the Nginx plugin using the following command:
2. Configure Nginx
Edit your Nginx configuration file to include your server name. Open the file with a text editor:
Add your subdomain in the server_name
directive:
Save the file and exit the editor. Then, test your Nginx configuration:
3. Create an A Record in Your Domain Registrar
Log in to your domain registrar (e.g., GoDaddy) and create an A
record pointing to the IP address of your server.
- Record Type: A
- Name: test.chaicode.com
- Value: IPv4 address of the server
NOTE: Its always a good idea to create a elastic/static IP for your server. This will make sure that your IP address doesn’t change on restart or reboot.
4. Obtain an SSL Certificate
Run Certbot to obtain an SSL certificate for your subdomain:
Follow the prompts:
- Enter the email address associated with your domain registrar account.
- Accept the terms of service.
- Press Enter to continue.
Certbot will automatically configure your Nginx to use the new certificate. You should see a message indicating that the certificate was successfully issued.
5. Access Your Site
You can now access your site using HTTPS:
6. Renewing the Certificate
To check if the certificate is close to expiring, run:
To renew the certificate, run:
This guide ensures that your Nginx server is secured with SSL, making your site accessible over HTTPS.