Ravindra BagaleCourses & study guides मराठी Track your progress

13. Multiple Websites on One Server and HTTPS with Certbot

Chala mitrano, companies madhe ekach server var kadhi kadhi anek websites chaltat – yourdomain.com, blog.yourdomain.com, shop.yourdomain.com. Nginx madhe yala server blocks mhantat, Apache madhe virtual hosts. Aaj aapan he Amazon Linux aani Ubuntu dogha var karuya, aani mag Certbot ne pratyek site la free HTTPS lavuya. Shevti HTTPS nit configure kela aahe ka te test kasa karaycha te pan baghuya. Ekdum simple aahe – ek site samjli ki dahavi pan tashich.

What you will learn in this chapter

  • How name-based virtual hosting works (the Host header)
  • Multiple sites with Nginx server blocks on Amazon Linux 2023 and Ubuntu
  • Multiple sites with Apache virtual hosts on Amazon Linux 2023 and Ubuntu
  • A safe catch-all default site and testing without DNS
  • Free HTTPS with Certbot, automatic renewal and HTTP → HTTPS redirect
  • Checking and hardening your TLS setup

Concepts in this chapter

  1. 13.1How Name-Based Virtual Hosting Works
  2. 13.2Multiple Sites with Nginx (Amazon Linux 2023 and Ubuntu)
  3. 13.3Multiple Sites with Apache (Amazon Linux 2023 and Ubuntu)
  4. 13.4HTTPS with Certbot (Let's Encrypt)
  5. 13.5Checking and Hardening Your TLS Setup

The chapter recap is at the end of the last concept page.

Chapter 13: Multiple websites and HTTPS — practice tasks

Open chapter lessons · Full guided lab: certbot https redirect renewal dry run (not repeated here)

13.1 Two sites on one nginx

MediumRetail

Why: Name-based hosting saves cost, but a wrong default server can show the wrong shop.

What: Serve a.lab and b.lab from different folders.

How:

  1. Add both names to /etc/hosts → 127.0.0.1.
  2. Create two server blocks with server_name a.lab / b.lab.
  3. sudo nginx -t && sudo systemctl reload nginx
  4. curl -s a.lab; curl -s b.lab

Expected output: Different page text for each name.

Hint

Add a catch-all default_server that returns 444.

Answer / how to check
  1. curl -s -H 'Host: x.lab' 127.0.0.1 gets no shop page.

13.2 Self-signed HTTPS for a lab site

MediumIT

Why: You can practise TLS without a real domain.

What: Create a self-signed cert and serve HTTPS.

How:

  1. openssl req -x509 -nodes -newkey rsa:2048 -days 7 -subj '/CN=a.lab' -keyout a.key -out a.crt
  2. Add listen 443 ssl; ssl_certificate / ssl_certificate_key.
  3. curl -vk https://a.lab/ 2>&1 | grep -iE 'subject|TLS'

Expected output: subject: CN=a.lab and TLSv1.3/1.2.

Hint

-k ignores trust because it's self-signed.

Answer / how to check
  1. Browser warns (not trusted) — expected for self-signed.

13.3 Check HTTP→HTTPS redirect

EasyBanking

Why: Login pages must never stay on HTTP.

What: Prove port 80 redirects.

How:

  1. Add return 301 https://$host$request_uri; to the port 80 block.
  2. curl -sI http://a.lab/

Expected output: 301 with Location: https://a.lab/.

Hint

See linked certbot lab for real domains.

Answer / how to check
  1. Status 301 and https Location.

Extended teaching notes

Why this lesson matters

Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.

Apply the fix across stacks

Same class of bug, same idea in every language.

Java / Spring Boot

Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.

ASP.NET Core

EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.

Node.js / Express

helmet, parameterised SQL, npm audit, avoid eval and shell concat.

Python / Django / Flask / FastAPI

ORM, autoescape, pip-audit, Bandit; never shell=True with user input.

PHP / Laravel

PDO/Eloquent, Blade escaping, composer audit.

Go / Ruby

database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.

nginx / Apache / Tomcat

Hide versions, TLS, security headers, least-open ports.

MySQL / PostgreSQL / MongoDB / Redis

Private networks, auth on, least-privilege users, no 0.0.0.0/0.

AWS / Azure / GCP

Roles not long-lived keys, private data stores, cloud audit logs on.

Mini case study

Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.

Defender's worksheet (do this today)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.

Indian workplace (sample data)

Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).

Global practice

Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.

Everyday analogy

Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.

Key terms

  • Control: a safeguard (patch, config, process, detection).
  • Finding: a weakness backed by evidence.
  • Remediation: the fix plus how you verified it.
  • Scope: systems you have written permission to touch.
  • Least privilege: only the access the task needs.
  • Defence in depth: several layers so one failure does not end the story.

Common mistakes

  • Skipping written permission "just for a quick scan".
  • Practising on hostel, office or public targets without authorisation.
  • Collecting tool output without writing the fix.
  • Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
  • Publishing screenshots that contain secrets, cookies or internal hostnames.

Recap

  • Evidence, fix, owner, date.
  • Own lab only.
  • Fix > spectacle.

Extra depth

Re-read the original short section at the top of the page, then this expansion. Together they should exceed a solid lesson length. If anything still feels thin, add your own lab screenshot and a paragraph in your notebook — that personal evidence is what interviews ask for.

  • Permission before tools.
  • Patch and config before exploits.
  • Logs and backups before blame.
  • Teach one junior the warning from this page.