In today’s digital landscape, securing your website with an SSL certificate is essential. Let’s Encrypt, a free, automated, and open certificate authority (CA), provides a simple and cost-effective solution for obtaining SSL certificates. In this article, we will guide you through the process of setting up Let’s Encrypt with Nginx on Ubuntu 23.10, ensuring a secure connection for your website visitors.
Prerequisites
Before we begin, there are a few prerequisites that need to be met in order to successfully install Let’s Encrypt with Nginx on Ubuntu 23.10:
- Ubuntu 23.10 installed with root access to the system.
- A domain name with an A record pointing to your server’s IP address.
Updating the System
To ensure that our system is up to date, we will first update Ubuntu 23.10. Open the terminal and run the following command:
apt dist-upgrade
Installing Snapd
Next, we will install the snapd
package, which is required for installing Let’s Encrypt. Run the following command:
apt install snapd
After the installation is complete, update snapd
by running the following commands:
snap install core snap refresh core
Installing Nginx
To install Nginx, the popular web server software, run the following command:
apt install nginx
Once the installation is complete, start Nginx and enable it to run on system startup with the following commands:
systemctl start nginx systemctl enable nginx
To verify that Nginx is running correctly, you can open your web browser and enter your server’s IP address. If you see the default Nginx landing page, then Nginx is successfully installed.
Installing Certbot
Certbot is a tool provided by Let’s Encrypt for automatically obtaining and renewing SSL certificates. To install Certbot for Nginx, run the following command:
snap install --classic certbot
Setting up Nginx vHost for the SSL Certificate
Before we can obtain an SSL certificate, we need to configure the Nginx virtual host for our domain. Open the virtual host configuration file using your preferred text editor:
nano /etc/nginx/conf.d/example.com.conf
Replace example.com
with your actual domain name in the configuration file. Update the root
directive to point to the location of your website files. Here is an example configuration:
server { listen 80; listen [::]:80; root /var/www/example.com/public_html; index index.html; server_name example.com www.example.com; access_log /var/log/nginx/example.com.access.log; error_log /var/log/nginx/example.com.error.log; location / { try_files $uri $uri/ =404; } }
Save the file and exit the text editor. To test the Nginx configuration for any syntax errors, run the following command:
nginx -t
If there are no errors, reload Nginx to apply the new configuration:
systemctl reload nginx
Setting up the SSL Certificate
Now that our Nginx virtual host is configured, we can obtain the SSL certificate using Certbot. Run the following command:
certbot --nginx -d example.com -d www.example.com
Replace example.com
with your actual domain name. Certbot will automatically edit the Nginx configuration file and enable HTTPS access.
During the installation process, you will be prompted to accept the terms of service. Once the installation is complete, you will receive a confirmation message indicating the location of your certificate and key files:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem
- Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem
- Your cert will expire on 2020-09-05. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option.
- Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now.
Congratulations! Your SSL certificate for example.com
and www.example.com
has been successfully installed. You can now access your website using https://
and verify the secure connection with the lock icon in the URL bar.
Automating Certificate Renewal
Let’s Encrypt SSL certificates expire after a certain period of time. To ensure uninterrupted service, it is important to set up automated certificate renewal. Fortunately, Certbot provides an easy way to accomplish this.
To automatically renew all your certificates, run the following command:
certbot renew
You can add this command to a cron job to automate the renewal process. Certbot will check for expiring certificates and renew them if necessary.
Conclusion
In this article, we have walked through the process of installing Let’s Encrypt SSL certificates with Nginx on Ubuntu 23.10. By following these steps, you have successfully secured your website and ensured a safe browsing experience for your visitors.
Shape.host offers a wide range of reliable and scalable cloud hosting solutions, including Cloud VPS. With Shape.host, you can take advantage of their expertise and industry-leading technologies to optimize your website’s performance and security. Visit Shape.host today to learn more about their services and take your online presence to the next level.