Skip to content
Wonderful Code See
Wonderful Code See

Master the Code, Shape Your Future

  • Home
  • IT Consulting
  • Artificial Intelligence
    • AI Applications
  • CS Fundamentals
    • Data Structure and Algorithm
    • Computer Network
  • System Design
  • Programming
    • Python Stack
    • .NET Stack
    • Mobile App Development
    • Web Development
    • Unity Tutorials
    • IDE and OA
  • Technology Business
    • Website building tutorials
  • Dev News
Wonderful Code See

Master the Code, Shape Your Future

Free HTTPS Certificate Setup: A Complete Guide for CentOS 7 + Nginx + Let’s Encrypt

WCSee, June 26, 2025June 26, 2025

In modern web deployment, configuring multiple sites with Nginx—whether using different domains or subdomains—and enabling HTTPS has become a standard best practice. HTTPS not only enhances the security and trustworthiness of your websites but also contributes positively to SEO rankings.

This guide walks you through a full example of hosting two static sites on yourdomain.com and its subdomain tgame.yourdomain.com using Nginx and Certbot on CentOS 7. Whether you’re a beginner webmaster or a DevOps engineer, this tutorial will help you implement a free HTTPS solution with automated certificate management using Let’s Encrypt.


🧾 1. Environment Requirements

ComponentDescription
OSCentOS 7 or later
Web ServerNginx
HTTPS CertificateLet’s Encrypt (via Certbot)
Domainsyourdomain.com, tgame.yourdomain.com
PrerequisitesValid domains with DNS correctly pointing to your public server IP

🛠️ 2. Install Required Packages

Step 1: Install EPEL and Nginx

sudo yum install epel-release -y
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

Step 2: Install Certbot and Nginx Plugin

sudo yum install certbot python2-certbot-nginx -y

📁 3. Create Website Root Directories (Optional but Recommended)

To better organize content for multiple sites, create separate directories for each domain:

sudo mkdir -p /var/www/yourdomain.com/html
sudo mkdir -p /var/www/tgame.yourdomain.com/html
sudo chown -R nginx:nginx /var/www

You can now place your index.html or other static content in the respective folders.


⚙️ 4. Configure Nginx Virtual Hosts

Step 1: Create Config for Main Domain

File: /etc/nginx/conf.d/yourdomain.com.conf

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    root /var/www/yourdomain.com/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Step 2: Create Config for Subdomain

File: /etc/nginx/conf.d/tgame.yourdomain.com.conf

server {
    listen 80;
    server_name tgame.yourdomain.com;

    root /var/www/tgame.yourdomain.com/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Step 3: Test and Reload Nginx

sudo nginx -t
sudo systemctl reload nginx

🌐 5. Set Up DNS Records

Log in to your DNS provider (e.g., Aliyun, Cloudflare, GoDaddy) and add the following A records:

TypeNameValue (Server IP)
A@123.123.123.123
Awww123.123.123.123
Atgame123.123.123.123

Tips:

  • Use dig tgame.yourdomain.com +short or ping to verify DNS resolution.
  • If using Cloudflare, disable proxy (make icon gray) for A records to ensure Let’s Encrypt validation can succeed.

🔐 6. Obtain and Configure HTTPS Certificates

Use Certbot to automatically issue certificates and update your Nginx config.

Issue for Individual Sites

sudo certbot -nginx -d yourdomain.com -d www.yourdomain.com
sudo certbot -nginx -d tgame.yourdomain.com

Recommended: Issue for Multiple Domains at Once

sudo certbot -nginx \
  -d yourdomain.com \
  -d www.yourdomain.com \
  -d tgame.yourdomain.com

Certbot will automatically:

  • Validate domain ownership
  • Issue a 90-day certificate
  • Update your Nginx configs for HTTPS
  • Add HTTP → HTTPS permanent redirects (301)

🔁 7. Test Auto-Renewal

Let’s Encrypt certificates are valid for 90 days. Certbot sets up auto-renewal using cron or systemd. Test it manually with:

sudo certbot renew -dry-run

📊 8. Verify Deployment

Open your browser and check:

  • https://yourdomain.com
  • https://www.yourdomain.com
  • https://tgame.yourdomain.com

You should see your site content and a secure HTTPS (green padlock) icon.


❗ 9. Common Issues & Fixes

ProblemLikely CauseSolution
NXDOMAIN errorDNS not resolvedCheck DNS records; wait for propagation
403 ForbiddenIncorrect permissions or missing filesCheck ownership and presence of index.html
Certificate failurePort 80/443 blocked by firewall/proxyOpen required ports or stop conflicting services
HTTPS error pageBrowser cache or Nginx not reloadedClear cache, test config with nginx -t, reload

✅ Conclusion

With this step-by-step guide, you’ve learned how to:

  • Install and configure Nginx on CentOS 7
  • Host multiple sites with individual root directories
  • Use Let’s Encrypt to issue free HTTPS certificates
  • Enable automatic renewal to ensure long-term uptime
Please follow and like us:
RSS
Facebook
Facebook
fb-share-icon
X (Twitter)
Visit Us
Follow Me
Tweet
Pinterest
Pinterest
fb-share-icon
Post Views: 0

Related posts:

Clone a WordPress with ASP.NET and React Part 1: Initialize Project Structure with AI How to Build a Website from Scratch (Step-by-Step Guide for Beginners) Choose the Right Website Platform or Builder | Building Website Tutorials Part 2 How to Check SSL/TLS Versions and Cipher Suites on macOS and Windows Set Up and Customize Website Using WordPress | Building Website Tutorials Part 4 Unity in Practice 0002 – Install Unity and Visual Studio IT Audit Guide 05: IT Audit Process (Step-by-Step Guide) IT Audit Guide Part 7: IT Audit Deliverables
Website building tutorials free https certificateLet’s Encrypt

Post navigation

Previous post

Leave a Reply Cancel reply

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

Recent Posts

  • Free HTTPS Certificate Setup: A Complete Guide for CentOS 7 + Nginx + Let’s Encrypt
  • Understanding Architecture Evolution: Monolith, Microservices, and PBC
  • A Comprehensive Guide to AI Agents: Definition, Role, Examples, and Future Prospects
  • The History of Artificial Intelligence (AI): From Turing to ChatGPT
  • Clone a WordPress with ASP.NET and React Part 2: Create ASP.NET Projects Code Files with AI
  • Clone a WordPress with ASP.NET and React Part 1: Initialize Project Structure with AI
  • Clone a WordPress with ASP.NET Core and React: An AI-Assisted Development Journey
  • Artificial Intelligence (AI) Learning Roadmap for Beginners in 2025
  • Set Up and Customize Website Using WordPress | Building Website Tutorials Part 4
  • How to Export Wide Excel sheet to PDF Without Cutting Columns

Recent Comments

    Categories

    • Artificial Intelligence (6)
      • AI Applications (1)
    • CS Fundamentals (1)
      • Computer Network (1)
    • IT Consulting (24)
    • Programming (20)
      • .NET Stack (3)
      • IDE and OA Tool Tips (1)
      • Python Stack (1)
      • Unity Tutorials (15)
    • System Design (5)
    • Technology Business (7)
      • Website building tutorials (6)

    Archives

    • June 2025 (5)
    • May 2025 (52)
    ©2025 Wonderful Code See | WordPress Theme by SuperbThemes
    Manage Consent
    To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
    Functional Always active
    The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
    Preferences
    The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
    Statistics
    The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
    Marketing
    The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
    Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
    View preferences
    {title} {title} {title}