There are two types of virtual hosting: named-based and IP-based. Named-based virtual hosting, which we will be discussing today, describes a scenario in which a webmaster is hosting multiple websites on a single IP address – even though these websites all have different names. IP-based hosting, as you may have guessed, describes hosting each website on its own individual IP address.
Why Consider Name-Based Hosting?
Name-based hosting is a great option for many, because IP addresses can be a tough resource to come by (but don’t worry – at URPad, we have plenty available!). That’s because IPv4, which is what powers most of the web as we know it, is rapidly depleting. In fact, the American Registry for Internet Numbers (ARIN) has all but stopped allocating new IP blocks – even to the most qualified internet service providers (ISPs). However, there are still vendors out there (including URPad) where large quantities of IPv4 are still available.
The Depletion of IPv4 in the United States
This shortage of IP addresses is a major reason many people use name-based hosting. In 1981, the engineers who invented the internet created 4.3 billion addresses. This was a part of the IPv4 specification. This was the first (and only!) version of the internet protocol. Today, very few of these original 4.3 billion IP addresses are still available.
It’s also worth noting that some webmasters (although not many) have begun moving to a new form of IP known as IPv6. IPv6 was approved in 1998 and was designed to be infinite. Well, sort of infinite. IPv6 allows 340 undecillion (36 zeros!!) addresses, so there’s no real danger of running out any time soon. Anecdotally, Facebook is actually one of the early adopters who has already moved over to IPv6. About 9% of the internet has followed suit, according to Facebook engineer Paul Saab.
In the meantime, though, switching over to IPv6 is not an option for everyone. However, those who are not yet able to make the switch can still most multiple sites on a single IP address using name-based hosting. Setting this up in a virtual environment is an incredibly effective solution, as it enables the server’s owner to experience total freedom when managing his/her server setup.
The Great Alternative to Multiple IP Addresses
When only a single IP address is being used to host multiple sites, servers distinguish between domains by looking into “host headers” to determine which site is actually being requested. As an example, imagine that you were hosting both YourSite.com and YourSite.net with both pointing to the same IP address. The files for each of these sites are stored in specific directories. Files for YourSite.com may be found in /var/www/user/YourSite1/site while the files for YourSite.net may be found in /var/www/user/YourSite2/site. In this scenario, when a request is may for YourSite.com, the contents are pulled from /var/www/user/YourSite1/site.
The same is also true of subdomains. As an example, the same can be applied to subdomains such as blog.YourSite.com and widget.YourSite.com if you choose to employ the same hosting set up.
Pros of Choosing a Name-Based Virtual Host
Just like anything else in life, there are pros and cons to choosing a name-based hosting method. First, we will take a look at some of the positive attributes to this decision.
Name-Based Hosting is Simple
With name-based hosting, you’ll only have to configure your DNS to map each hostname to a single IP address. With IP-based hosting, your DNS configuration will be different for each site you manage. This is ideal unless you have a specific reason for sticking with IP-based hosting.
Name-Based Hosting Only Requires 1 IP Address
We mentioned above how difficult it is becoming to get IPs. What we were talking about is a unique problem that is not specific to the United States. IP addresses in Asia were virtually depleted in 2011 and Europe followed a year later.
While many US-based companies have enjoyed easy access to large quantities of IPv4 in the past, this is no longer the case. Even requesting IPv4 from ARIN has become a painstaking process that requires thorough documentation regarding the justification of the request being submitted. At this point, if you don’t already have access to IP addresses, you’re going to have to buy them from a registered ISP.
Name-Based Hosting is Cost-Effective
Many site owners buy separate networks works when hosting multiple sites on individual IP addresses. This isn’t a necessary expense, but it’s something that we’ve seen frequently. Name-based hosting eliminates the need for this altogether, lowering the total investment significantly.
Cons of Choosing a Name-Based Virtual Host
Where there are pros, there must be cons. To tell the full story on name-based hosting, it’s important that we disclose the possible drawbacks that users may experience when going this route.
The SSL/TLS Handshake
A major setback when managing multiple websites on a single IP address is the impact this has on an SSL/TLS (security protocols which can be used to enhance site security) handshake. Because of the multiple sites appearing on a single IP address, the server won’t be able to tell which certificate to present during the handshake. That is because each site would be using its own SSL/TLS certificate.
Sure, a single certificate can be used to cover multiple names through the subjectalname field (or through the use of wildcards), this method is still limited by administrative considerations. When wildcards are used, the matching rules must still be account for. However, there is a TLS extension called Server Name Identification (SNI) that can remedy this. The problem is that older browsers won’t recognize or support SNI.
Potential DNS Failure
Name-based hosting can lead to issues with DNS if a server is not configured properly. Even when the proper IP address is know, a site that is hosted virtually can still be difficult to access via domain. Extreme cases can still require that the user types the site’s exact IP address into the address bar to retrieve the site.
How to Set Up Your Name-Based Virtual Host on URPad
Step 1: Assign the IP address on the server that will be accepting requests for the host. This is configured through the NameVirtualHost directive. You can assign a specific address to the directive or, if possible, assign all IP addresses on this server. To do so, you must edit the httpd.conf file.
Here’s what the file will look like when assigning a particular address. For this example, we’ll use 123.12.123.12 as our IP address:
NameVirtualHost 123.12.123.12
And here’s what the file will look like when you are assigning all IP addresses:
NameVirtualHost *
You can also specify the port within the argument if you want. Using an example port of :222, your new line file would look like one of these:
NameVirtualHost 123.12.123.12:222
NameVirtualHost *:222
Pretty simple, right?
Step 2: Create a <VirtualHost> block for each host. The argument to the <VirtualHost> directive should match an existing NameVirtualHost directive. To continue with the same IP address from the example above, the block would look like this:
<VirtualHost 123.12.123.12>
</VirtualHost>
For each block, there are minimum directives to be fulfilled and these includes:
- ServerName (this designates which host is served)
- Docutment Root (this shows where the content for that host is stored in the filesystem)
Going back to the YourSite.com example above, let’s say that you have 3 subdomains: blog, widget and profile. So each <VirtualHost> block would appear as follows:
<VirtualHost 123.12.123.12>
ServerName blog.YourSite.com
DocumentRoot /user/local/apache/blog
</VirtualHost>
<VirtualHost 123.12.123.12>
ServerName widget.YourSite.com
DocumentRoot /user/local/apache/widget
</VirtualHost>
<VirtualHost 123.12.123.12>
ServerName profile.YourSite.com
DocumentRoot /user/local/apache/widget
</VirtualHost>
Some servers use more than one name to be more accessible. This can be done using the ServerAlias directive, which is placed inside the <VirtualHost> block:
<VirtualHost 123.12.123.12>
ServerName blog.YourSite.com
DocumentRoot /usr/local/apache/blog
ServerAlias blog
</VirtualHost>
When a request is made, the server checks if it uses an IP address that matches that in the NameVirtualHost directive. If the IP does match, the server will look through each <VirtualHost> block with a matching IP address to find the appropriate ServerName that matches the requested host name. If there is a match found, then that is the configuration that is used. If no matching virtual host if found, then the virtual host listed with a matching IP address will be used.
Step 3: Fine-Tune Virtual Host Configuration. To do this, you have to add more directives inside the <VirtualHost> block. However, that means you still have to verify whether each particular directive is allowed by checking the Context of each directive.
Name-Based Virtual Hosting with URPad
At URPad, we try to make it as easy as possible to keep your data safe and your site online. To get the most out of your VPS, check out blog regularly for additional tips on how to do just that. And if you need additional assistance, feel free to use the LiveChat feature on our site. At URPad, we’re always here to help!