🚀 DevOps Certified Professional
📅 Starting: 1st of Every Month 🤝 +91 8409492687 | 🤝 +1 (469) 756-6329 🔍 Contact@DevOpsSchool.com

Configuring Virtual Hosting in Apache

Linux

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

“Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers).”

Wikipedia

How Does Apache Know Which Site to Serve?


The short answer to your specific case: apache will serve the FIRST overlapping virtual host. Since 000-default is before fc.localhost in the alphabet the first virtualhost is loaded and served.

To answer what i assume is the follow up question: You can host many sites on the same IP:PORT using named VirtualHosts

The host field in the http request header identifies which site (virtual
host) to serve:

Matched against the containers in the configuration file

A More Complete Virtual Host Definition

You can put (almost) any directive inside a virtual host container For example, it’s common to write separate logs for each site

Name Resolution

  1. In the “real world” our East and West sites would each have an entry in DNS (Domain Name Service)
  2. Our demonstration system uses only /etc/hosts for name resolution: