Hosting sites on the Cloud server gives much flexibility compared to shared hosting. You can install whatever you like, scale up or down, and configure for better performance and cost-optimization. If you are running multiple business sites but don’t want to host them separately, you can take advantage of Virtual Server in web servers. Let’s take a look at this scenario. I have the following two sites which I would like to point to my one cloud VM.

lab.geekflare.com gf.dev

Before implementation, let’s understand how it works. The concept to have multiple websites on a single web server instance is called Virtual Server. It is defined in the configuration file along with the URL. When a request is made to a defined URL, the webserver would serve the traffic from the respective Document Root.

Configure Virtual Host in Apache to host multiple domains

Login into Apache HTTP Server Go to the apache conf location. ( in default installation – you will find it here /etc/httpd/conf/httpd.conf) Take a backup of httpd.conf file 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

Login to Nginx server Go to the location where you’ve installed Nginx. (in default location – you will find it here /etc/nginx/)

There are multiple ways to achieve this. Either you can modify nginx.conf file or custom file if you have any. You may also create a custom.conf under conf.d folder. Choose what works for you and take a backup if modifying an existing file.

Create a 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

Don’t forget to update the DNS record of your URL to map to server IP. Once done, you should be able to access the URLs which are getting served through the above configuration you made.

Conclusion

That was the quick guide to hosting multiple domains in a single web server instance like Apache or Nginx. Once your website is live, don’t forget to test it against security vulnerabilities.

Host Multiple Domains on One Server or IP with Apache or Nginx - 37Host Multiple Domains on One Server or IP with Apache or Nginx - 32Host Multiple Domains on One Server or IP with Apache or Nginx - 99Host Multiple Domains on One Server or IP with Apache or Nginx - 83Host Multiple Domains on One Server or IP with Apache or Nginx - 96Host Multiple Domains on One Server or IP with Apache or Nginx - 86