VPSWala Blog

How To Setup Subdomains & LetsEncrypt On NGINX

September 9, 2024, Written by 0 comment

Managing several domains and ensuring them with SSL/TLS certificates is common in running a website. This post will walk over creating subdomains and obtaining free SSL/TLS certificates on an NGINX web server with LetsEncrypt.

Prerequisites

  • An NGINX web server housed on your machine
  • A domain name you own and manage
  • SSH access to your server

Install LetsEncrypt Client

We must first install the LetsEncrypt client so that we may get and renew SSL/TLS certificates:

sudo apt install certbot python3-certbot-nginx -y

Set NGINX for Subdomains

We will next arrange NGINX to manage our subdomains. Write a fresh configuration file for every subdomain:

sudo nano /etc/nginx/conf.d/subdomain.example.com.conf

Add the following material, substituting your real subdomain for “subdomain.example.com” and “path/to/your/website” with the proper path:

server {
    listen 80;
    server_name subdomain.example.com;

    location / {
        root /path/to/your/website;
        index index.html index.htm index.nginx-debian.html;
    }
}

Proceed this with every subdomain you wish to set up.

Also Check: How to Install Docker on Ubuntu 22.04

Get SSL/TLS Certificates via LetsEncrypt

Let’s now obtain SSL/TLS certificates with LetsEncrypt:

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

Swap your real domain and subdomains for “example.com,” “www.example.com,” and “subdomain.example.com”. Use the prompts to finish the certificate-acquiring process.

Check SSL/TLS Settings

Visit your domain and subdomain in a web browser to confirm that your SSL/TLS setup is operational. See the padlock icon to indicate a safe connection.

Automate Certificate Renewal

Since LetsEncrypt certificates are good for ninety days, we must arrange automatic renewal. Make a cron task to update the certificates:

sudo crontab -e

Add this line to renew the certificates once a month:

0 0 1 * * /usr/bin/certbot renew --quiet

Conclusion

At last Using LetsEncrypt, you have now established subdomains and acquired free SSL/TLS certificates on your NGINX web server. For maximum performance and security, keep your system and NGINX setup current.

Consider VPSWala if you’re searching for a dependable and reasonably priced hosting option. To meet your website’s demands, VPSWala provides various VPS and Shared hosting solutions. For hosting your website and administering your domains and SSL/TLS certificates, VPSWala is an excellent option because of its strong infrastructure, round-the-clock customer service, and affordable prices. VPSWala offers a hosting solution that will work for you, regardless of the type of website you manage, from a personal blog to a complex online application.

vpswala Admin

Savita Sathe is an experienced writer and editor with over 10+ years of professional experience creating engaging content across industries. Whether it's blogs, whitepapers, website copy, emails, social media posts, or more. She develops effective hosting and tech content that helps brands connect with their audiences and achieve business goals.

Leave a reply

Your email address will not be published. Required fields are marked *