How to Host Multiple Websites on Your Dedicated Server

Hosting multiple websites on your dedicated server is a cost-effective and efficient way to utilize server resources. As a QuickServers.net customer, this guide will help you set up multiple websites on your server step by step.


Step 1: Update Your Server

Before making any changes, ensure your server is up to date.

  • For CentOS:
    sudo yum update -y  
    
  • For Ubuntu/Debian:
    sudo apt update && sudo apt upgrade -y  
    

Reboot your server if necessary:

sudo reboot  

Step 2: Install and Configure a Web Server

Install a web server to host your websites. Popular options include Apache and Nginx.

  • Install Apache:

    sudo apt install apache2 -y  # For Ubuntu/Debian  
    sudo yum install httpd -y   # For CentOS  
    
  • Install Nginx:

    sudo apt install nginx -y  # For Ubuntu/Debian  
    sudo yum install nginx -y  # For CentOS  
    

Start and enable the web server:

sudo systemctl start apache2   # For Apache on Ubuntu/Debian  
sudo systemctl start httpd     # For Apache on CentOS  
sudo systemctl start nginx     # For Nginx  

sudo systemctl enable apache2  # For Apache on Ubuntu/Debian  
sudo systemctl enable httpd    # For Apache on CentOS  
sudo systemctl enable nginx    # For Nginx  

Step 3: Set Up Virtual Hosts (Apache) or Server Blocks (Nginx)

To host multiple websites, create a virtual host or server block for each domain.

  • For Apache:

    1. Create a new configuration file for each website:
      sudo nano /etc/apache2/sites-available/example.com.conf  
      
    2. Add the following configuration:
      <VirtualHost *:80>  
          ServerName example.com  
          ServerAlias www.example.com  
          DocumentRoot /var/www/example.com  
          ErrorLog ${APACHE_LOG_DIR}/example.com_error.log  
          CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined  
      </VirtualHost>  
      
    3. Enable the site and reload Apache:
      sudo a2ensite example.com.conf  
      sudo systemctl reload apache2  
      
  • For Nginx:

    1. Create a new configuration file for each website:
      sudo nano /etc/nginx/sites-available/example.com  
      
    2. Add the following configuration:
      server {  
          listen 80;  
          server_name example.com www.example.com;  
          root /var/www/example.com;  
      
          access_log /var/log/nginx/example.com_access.log;  
          error_log /var/log/nginx/example.com_error.log;  
      }  
      
    3. Link the configuration file and reload Nginx:
      sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/  
      sudo systemctl reload nginx  
      

Step 4: Create Document Roots for Each Website

Create a directory to store your website files.

sudo mkdir -p /var/www/example.com  
sudo chown -R $USER:$USER /var/www/example.com  

Add an index.html file to test the setup:

echo "<h1>Welcome to example.com!</h1>" | sudo tee /var/www/example.com/index.html  

Step 5: Update DNS Settings

Point each domain to your server's IP address. Update the DNS A record for your domains in your domain registrar's control panel. Allow some time for the changes to propagate.


Step 6: Secure Your Websites with SSL

Secure your websites with an SSL certificate using Let's Encrypt.

Install Certbot:

sudo apt install certbot python3-certbot-apache -y  # For Apache  
sudo apt install certbot python3-certbot-nginx -y   # For Nginx  

Obtain and install the certificate:

sudo certbot --apache  # For Apache  
sudo certbot --nginx   # For Nginx  

Verify the SSL setup by visiting your websites using https.


Step 7: Monitor and Maintain

Regularly monitor your server's performance and update your web server software to ensure optimal performance.

  • Monitor logs:
    tail -f /var/log/apache2/access.log  # Apache  
    tail -f /var/log/nginx/access.log   # Nginx  
    
  • Update software:
    sudo apt update && sudo apt upgrade -y  
    

By following these steps, you can efficiently host multiple websites on your dedicated server. If you need further assistance, visit QuickServers.net.

Was this answer helpful? 0 Users Found This Useful (0 Votes)