Implementing a virtual hosting paradigm

If we wish to host multiple sites on one server, we can do so with virtual hosting. Virtual hosting is a way to uniquely handle multiple domain names according to their name. The technique is surprisingly simple: we just look at the incoming Host header and respond accordingly. In this task, we're going to implement simple name based virtual hosting for static sites.

Getting ready

We'll create a folder called sites, with localhost-site and nodecookbook as subdirectories. In localhost-site/index.html we'll write the following:

<b> This is localhost </b>

And in nodecookbook/index.html we'll add the following code:

<h1>Welcome to the Node Cookbook Site!</h1>

For local testing, we'll want to configure our system ...

Get Node Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.