Host Multiple Websites on Single Cloud Server with Apache or NGINX

Image is loading...

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

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 syam.me  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 [email protected]
   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 [email protected]
   DocumentRoot /var/www/html/syam
   ServerName syam.me
   ErrorLog logs/syam.me-error_log
   CustomLog logs/syam.me-access_log common
</VirtualHost>

Now we need to restart the Apach2 server.

sudo service apache2 restart



NGINX

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 syam.me  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 syam.me;
   location / {
       try_files $uri $uri/ =404;
   }
}

Now we need to restart the NGINX server.

sudo service nginx restart

Have a nice code !

You May Also Like

About the Author: Syamlal CM

Hi, I'm Syamlal, the co-founder of Redmonark. I'm a developer, writer and also have a little bit of experience in graphic designing.

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.