13. Multiple Websites on One Server and HTTPS with Certbot
13.3 Multiple Sites with Apache (Amazon Linux 2023 and Ubuntu)
# 00-default.conf (loads first, so it is the fallback)
<VirtualHost *:80>
ServerName default.invalid
DocumentRoot /var/www/html
</VirtualHost>
# site1.conf
<VirtualHost *:80>
ServerName site1.example.com
DocumentRoot /var/www/site1
ErrorLog /var/log/httpd/site1_error.log
</VirtualHost>
# site2.conf
<VirtualHost *:80>
ServerName site2.example.com
DocumentRoot /var/www/site2
ErrorLog /var/log/httpd/site2_error.log
</VirtualHost>
# Ubuntu Apache: enable sites (log path ${APACHE_LOG_DIR})
sudo a2ensite site1.conf site2.conf
sudo a2dissite 000-default.conf # optional
sudo apache2ctl configtest && sudo service apache2 reload
Test without buying domains:
curl -H "Host: site1.example.com" http://localhost # Welcome to site1
curl -H "Host: site2.example.com" http://localhost # Welcome to site2
curl -I http://localhost # default block answers
From your laptop, add both names to your hosts file pointing to the server's Elastic IP, then open them in the browser. In Chapter 12 we'll replace this trick with real DNS records.
| Step | Amazon Linux 2023 | Ubuntu |
|---|---|---|
| Config folder | /etc/httpd/conf.d/site1.conf | /etc/apache2/sites-available/site1.conf |
| Enable | Automatic (any .conf in conf.d) | sudo a2ensite site1.conf |
| Log path | /var/log/httpd/site1_error.log | ${APACHE_LOG_DIR}/site1_error.log |
| Test | sudo apachectl configtest | sudo apache2ctl configtest |
| Reload | sudo service httpd reload | sudo service apache2 reload |
| Show vhosts | sudo apachectl -S | sudo apache2ctl -S |
Ravindra Bagale's Tip
On Amazon Linux, if you keep an old copy in conf.d named site1-old.conf, Apache loads that too – and you get two vhosts with the same name! Many students don't realise this. Always end backups with .bak, not .conf.
Ravindra Bagale's Tip – मराठी
Amazon Linux वर conf.d मध्ये जुनी copy site1-old.conf नावाने ठेवली तर Apache ती पण load करतो – मग एकाच नावाचे दोन vhosts! बऱ्याच students ना हे कळत नाही. Backup नेहमी .bak ने संपवा, .conf ने नाही.
Ravindra Bagale's Tip – हिंदी
Amazon Linux पर conf.d में पुरानी copy site1-old.conf नाम से रखी तो Apache उसे भी load करता है – फिर एक ही नाम के दो vhosts! बहुत से students को यह पता नहीं चलता. Backup हमेशा .bak पर ख़त्म करो, .conf पर नहीं.
Lab
Repeat the two-site setup with Apache on Ubuntu. Run sudo apache2ctl -S and identify the default virtual host.
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)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- 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.