How do I add another domain to my Linode?
We're currently hosting example.com
on our Linode server, but we would like to add staging.example.com
and example.org
to our Linode as well.
1 Reply
There are a few steps you need to take in order to add additional domains to your Linode.
First, you will want to create A records for either your new domain or for your subdomain and point it to your Linode's IP address. Alternatively, you can create CNAME records and point it to your domain name that is currently hosted on your Linode.
If you are using the Linode DNS Manager, you can review how to add/create DNS records in this article here.
<hr>Once you've pointed the domain correctly to your Linode, you want to set up what is called a Name-Based Virtual Host. A name-based virtual host is a way for your web server to respond with different resources based on the domain name that was used when trying to access the server.
The instructions for setting up a virtual host will vary depending on the web server you use. Most people use one of the following:
For each virtual host, you would want to set a web server root directory. Most default configurations set it to something like /var/www/html/
. A common configuration to separate into virtual hosts would be to create subdirectories as follows:
/var/www/html/example.com
/var/www/html/example.org
/var/www/html/staging.example.com
(please note you will need to create the directories yourself using the mkdir command)
<hr>Once you've completed that and correctly configured your name-based virtual hosts, you should be good to go! Your web server should now return different content based on the domain name you accessed it with.
<hr>Bonus:
Sometimes, you want to redirect from one virtual host to another. This is useful if you want to force a redirect from http
to https
, or if you want to force example.com
to redirect to www.example.com
. This can be done with Redirect
rules. I've included an example configuration for Apache and Nginx below:
Apache: Redirect from example.com
to www.example.com
. (Learn More)
<VirtualHost *:80>
ServerName example.com
Redirect / http://www.example.com
</VirtualHost>
Nginx: Redirect from http
to https
. (Learn More)
server {
listen 80;
server_name www.example.com;
return 301 https://www.example.com$request_uri;
}