Monday, November 14, 2016

Host Multiple Domains on One Server/IP with Apache or nginx

Configure Apache/Nginx to host multiple websites
If you are on dedicated or VPS like DigitalOcean or any other server and planning to host multiple websites 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 DigitalOcean.
  1. bestflare.com
  2. usefulread.com
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

  • Login into Apache HTTP Server
  • Go to 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.
<VirtualHost *:80>
ServerAdmin hello@chandank.com
   DocumentRoot /opt/htdocs/bestflare
   ServerName bestflare.com
   ErrorLog logs/bestflare.com-error_log
   CustomLog logs/bestflare.com-access_log common
</VirtualHost>
<VirtualHost *:80>
   ServerAdmin hello@chandank.com
   DocumentRoot /opt/htdocs/usefulread
   ServerName usefulread.com
   ErrorLog logs/usefulread.com-error_log
   CustomLog logs/usefulread.com-access_log common
</VirtualHost>
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 into Nginx server
  • Go to virtual.conf location (in default location – you will find it here /etc/nginx/conf.d/virtual.conf)
  • Take a backup of virtual.conf
  • Create server block for both URL’s as I have shown below.
server {
listen 80;
   root /opt/htdocs/bestflare;
index index.html index.htm;
   server_name bestflare.com;
   location / {
       try_files $uri $uri/ =404;
   }
}
server {
   listen 80;
   root /opt/htdocs/usefulread;
   index index.html index.htm;
   server_name usefulread.com;
   location / {
       try_files $uri $uri/ =404;
   }
}
Note: Change the value for root, server_name based on your requirement.
  • Restart Nginx and test both URL’s

Why We Love OpenCart

1. OpenCart is Free

2. Open-Source, Customizable and Flexible

3. Responsive Design

4. Free and Paid Functionality Extensions

5. SEO Ready

6. Analytics, Statistics and Advanced Data Tracking

7. Secure Payment and Shipping Methods

8. Multi-Store and Multi-Lingual Capabilities

9. Coupons, Specials, Reward Points and Gift Vouchers

10. Large User Base and Community