Cover by David Mark Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required