Host Multiple Websites on Single Cloud Server with Apache or NGINX

If we have a cloud server with a medium or high specification, we can host multiple web apps in it with different domain names for each app. If we need to host a web app backend on any cloud server, it does require an HTTP web server. The most popular HTTP servers available are Apache and NGINX.

The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation. Now, Apache2 is used mostly.

NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy serverNGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

You can select either Apache2 or NGINX. Anyways I am covering both the technologies in this tutorial.

Let’s come to the topic.

APACHE2

Let us first take a look at the Apache2 configuration for hosting multiple websites.

Configure virtual host in Apache2

We need to configure the virtual host in Apache2 to handle multiple domain requests coming to the Apache server.

The configuration file can be found in the destination

/etc/httpd/conf/httpd.conf

Here I am configuring my Apache2 virtual host for two domains syamlal.com and techomoro.com as I show below. You have to change the value for ServerAdmin, DocumentRoot, ServerName, ErrorLog, CustomLog based on your requirement.

<VirtualHost *:80>
ServerAdmin contact@techomoro.com
   DocumentRoot /var/www/html/techomoro
   ServerName techomoro.com
   ErrorLog logs/techomoro.com-error_log
   CustomLog logs/techomoro.com-access_log common
</VirtualHost>
<VirtualHost *:80>
   ServerAdmin hi@syamlal.com
   DocumentRoot /var/www/html/syam
   ServerName syamlal.com
   ErrorLog logs/syamlal.com-error_log
   CustomLog logs/syamlal.com-access_log common
</VirtualHost>

Now we need to restart the Apach2 server.

sudo service apache2 restart

NGINX

Now we can try this with NGINX configuration.

Configure virtual host in NGINX

We need to configure the virtual host in NGINX to handle multiple domain requests coming to the NGINX server.

The configuration file can be found in the destination

/etc/nginx/conf.d/virtual.conf

Here I am configuring my NGINX virtual host for two domains syamlal.com  and techomoro.com as I show below. You need to change the value for root and server_name based on your requirement.

server {
listen 80;
   root /var/www/html/techomoro;
index index.html index.htm;
   server_name techomoro.com;
   location / {
       try_files $uri $uri/ =404;
   }
}
server {
   listen 80;
   root /var/www/html/syam;
   index index.html index.htm;
   server_name syamlal.com;
   location / {
       try_files $uri $uri/ =404;
   }
}

Now we need to restart the NGINX server.

sudo service nginx restart

Summary

Here in this article, we discussed the steps to host multiple websites on a single cloud server with Apache2 or NGINX.

2 thoughts on “Host Multiple Websites on Single Cloud Server with Apache or NGINX

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.