Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting two domains using only one VPS?

Tags:

dns

vps

hosting

Is it possible? Someone told me it is but I'm not sure.

If its possible, how should I do it? I have one /www folder where my website lies. How can I configure 2 different sites?

like image 786
Artemix Avatar asked Jan 26 '11 19:01

Artemix


People also ask

Can I host 2 domains on one hosting?

Absolutely. With the right type of hosting account, you can host as many websites as your particular hosting package will allow. Be sure to check with your hosting provider before you begin hosting more than one domain.

How many domains can I host on VPS?

There is no restrictions on number of domains/websites you can create on VPS. You can host any number of websites according to free disk space and resources available in VPS.

Can 1 server have 2 domains?

Can a single server be associated with multiple domains? Yes. This would be done by pointing those domains at your web server via DNS.

Can I have 2 domains on the same IP?

It is not possible to provide two domain names for the same Server IP address and get two different SSL certificates (one for each domain name). Also note that the use of Host Headers (which is how you can use a single IP for more than one SSL enabled domain) is not recommended for E-Commerce sites.


1 Answers

As complete beginner, I have been trying to host multiple domains on one Apache VPS. Tutorials had too much information that lead me to confusion.

Below I describe, for complete begginers, how to host multiple domains on one VPS server with Ubuntu and Apache.

IMPORTANT! You need to use root account to execute most operations.

IMPORTANT! If you have been trying to make some changes to apache configuration before, undo them.

Creating VirtualHosts

Create folders for your domains on server. For example:

/home/apache/domain1

/home/apache/domain2

Put index.html file in each folder with any text.

This is domain1
This is domain2

Go to /etc/apache2/sites-available folder.

/etc/apache2/sites-available

Create file domain1

sudo nano domain1

<VirtualHost *:80>
DocumentRoot /home/apache/domain1
ServerName domain1.com
ServerAlias www.domain1.com
</VirtualHost>

Create file domain2

sudo nano domain2

<VirtualHost *:80>
DocumentRoot /home/apache/domain2
ServerName domain2.com
ServerAlias www.domain2.com
</VirtualHost>

You can create subdomains same way.

sudo nano blog

<VirtualHost *:80>
DocumentRoot /home/apache/blog
ServerName blog.domain.com
ServerAlias www.blog.domain.com
</VirtualHost>

Enable created sites

sudo a2ensite domain1
sudo a2ensite domain2

Restart apache

sudo service apache2 reload

Redirecting domain to server

Created VirtualHosts will work only if you redirect your domain name to server IP. Domains are just names that can be translated to IP numbers.

Local computer

To test your configuration on local machine, you need to edit hosts file.

sudo nano /etc/hosts

It should look like this.

127.0.0.1       localhost domain1.com domain2.com

Hosts file tells your computer that domain needs to be redirected to local machine.

IMPORTANT! If you create entry in hosts file for existing domain, for example

127.0.0.1       stackoverflow.com

you will lose access to this website.

Server

In order to redirect domain to you web server, you need to create or modify "A"-type DNS record for given domain to IP address of your server. You can do it by panel control provided by your domain registrar.

If you do not know IP address of your server, log in to that server and type in command line:

ifconfig
like image 91
Rafal Avatar answered Sep 19 '22 01:09

Rafal