Lead Image © Saniphoto, Fotolia.com

Lead Image © Saniphoto, Fotolia.com

Set up subdomains with Apache and Nginx

Sublet

Article from ADMIN 62/2021
By
Set up virtual hosts on modern web servers for Apache and Nginx.

The shortage of addresses and the quest for efficient resource usage established web server virtualization well before the topic of virtual machines and containers gained its current prominence. In this article, I demonstrate how to use different fully qualified domain names (FQDNs) on the same physical system with virtual hosts.

Virtual Hosts

In the mid-1990s, a single web server (usually the Apache server, which quickly became the de facto standard on Linux) typically ran with a single IP address. Once installed and configured, it reliably delivered a web page – always the same page – after requests to that IP address.

Not only was it impractical to have a separate computer for each web server, no matter how small, but IPv4 addresses were becoming scarce. Virtualized hosts didn't exist yet, so in version 1.1 the Apache developers conjured up the strategy of virtual hosts as a solution. Suddenly it didn't matter how many FQDNs pointed to the same IP address: The web server took care of the correct distribution of requests.

That's why the web browser doesn't just contact the plain vanilla IP address that it gets from the domain name server (DNS) after resolving the FQDN, it additionally specifies the desired host name directly after the GET request with a HOST specification (e.g., over Telnet on port 80, as in Listing 1).

Listing 1

Virtual Host Output

$ telnet www.wintermeyer.de 80
Trying 89.221.14.204...
Connected to www.wintermeyer.de.
Escape character is '^]'.
GET / HTTP/1.1
HOST: www.wintermeyer.de
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.3
Date: Fri, 27 Nov 2020 14:00:25 GMT
Content-Type: text/html
Content-Length: 185
Connection:
...
Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus