How to Host MultiDomain in VPS or Dedicated Server (Apache & Nginx)

If you are on dedicated server or VPS in any server and planning to host multiple domain on a single server then here is how you can do it either with Apache HTTP or Nginx web server.

This assumes you have already mapped DNS to your host, like following two domains I have mapped to dedicated server.

Before you implement this, to give you an idea how it works. The concept to have multiple websites on a single instance is called Virtual Server. Virtual server configuration is defined within web server configuration and based on server/IP address, a request is getting forwarded to respective Document Root.

Configure Virtual Host in Apache to host multiple domains

  1. Login into Apache HTTP Server
  2. Go to apache conf location. ( in default installation – you will find it here /etc/httpd/conf/httpd.conf)
  3. Take a backup of httpd.conf file
  4. Create a VirtualHost container like below I have done for two domains.

Note: Change the value for ServerAdmin, DocumentRoot, ServerName, ErrorLog, CustomLog based on your requirement.

  • Restart Apache HTTP and test both urls

Configure Virtual Host in Nginx to host multiple domains

  1. Login into Nginx server
  2. Go to virtual.conf location (in default location – you will find it here /etc/nginx/conf.d/virtual.conf)
  3. Take a backup of virtual.conf
  4. Create server block for both URL’s as I have shown below.

Note: Change the value for root, server_name based on your requirement.

  • Restart Nginx and test both URL’s

Hope its help you to hosting multiple domains in single web server instance like Apache or Nginx.

Leave a Reply

Your email address will not be published. Required fields are marked *