Apache Multisite Setup

Host suar.services, cv.suar.services, and help.suar.services with Apache

Set up an Apache server to host suar.services, cv.suar.services, and help.suar.services with both HTTP and HTTPS support.


1. Install Apache

  1. Ensure Apache is installed and running:
    sudo apt update
    sudo apt install apache2
    sudo systemctl start apache2
    sudo systemctl enable apache2

2. Enable Required Apache Modules

Enable necessary modules for virtual hosts and SSL:

sudo a2enmod ssl
sudo a2enmod rewrite
sudo systemctl restart apache2

3. Set Up DNS Records

Ensure the following DNS records point to your server’s public IP:

  • A Record: suar.services<Your Public IP>
  • A Record: cv.suar.services<Your Public IP>
  • A Record: help.suar.services<Your Public IP>

4. Create Directories for Each Website

Create separate directories to store website files:

sudo mkdir -p /var/www/suar.services
sudo mkdir -p /var/www/cv.suar.services
sudo mkdir -p /var/www/help.suar.services

Set appropriate permissions:

sudo chown -R $USER:$USER /var/www/suar.services
sudo chown -R $USER:$USER /var/www/cv.suar.services
sudo chown -R $USER:$USER /var/www/help.suar.services

5. Add Test HTML Files

Add a sample HTML file to each directory to test the setup:

echo "<h1>Welcome to Suar.Services</h1>" > /var/www/suar.services/index.html
echo "<h1>Welcome to CV.Suar.Services</h1>" > /var/www/cv.suar.services/index.html
echo "<h1>Welcome to Help.Suar.Services</h1>" > /var/www/help.suar.services/index.html

6. Create Virtual Host Files

For suar.services:

sudo nano /etc/apache2/sites-available/suar.services.conf

Add the following:

<VirtualHost *:80>
    ServerAdmin info@suar.services
    ServerName suar.services
    ServerAlias www.suar.services
    DocumentRoot /var/www/suar.services

    ErrorLog ${APACHE_LOG_DIR}/suar.services_error.log
    CustomLog ${APACHE_LOG_DIR}/suar.services_access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin info@suar.services
    ServerName suar.services
    ServerAlias www.suar.services
    DocumentRoot /var/www/suar.services

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/suar.services/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/suar.services/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/suar.services_error.log
    CustomLog ${APACHE_LOG_DIR}/suar.services_access.log combined
</VirtualHost>

For cv.suar.services:

sudo nano /etc/apache2/sites-available/cv.suar.services.conf

Add:

<VirtualHost *:80>
    ServerAdmin info@suar.services
    ServerName cv.suar.services
    DocumentRoot /var/www/cv.suar.services

    ErrorLog ${APACHE_LOG_DIR}/cv.suar.services_error.log
    CustomLog ${APACHE_LOG_DIR}/cv.suar.services_access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin info@suar.services
    ServerName cv.suar.services
    DocumentRoot /var/www/cv.suar.services

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/cv.suar.services/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/cv.suar.services/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/cv.suar.services_error.log
    CustomLog ${APACHE_LOG_DIR}/cv.suar.services_access.log combined
</VirtualHost>

For help.suar.services:

sudo nano /etc/apache2/sites-available/help.suar.services.conf

Add:

<VirtualHost *:80>
    ServerAdmin info@suar.services
    ServerName help.suar.services
    DocumentRoot /var/www/help.suar.services

    ErrorLog ${APACHE_LOG_DIR}/help.suar.services_error.log
    CustomLog ${APACHE_LOG_DIR}/help.suar.services_access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin info@suar.services
    ServerName help.suar.services
    DocumentRoot /var/www/help.suar.services

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/help.suar.services/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/help.suar.services/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/help.suar.services_error.log
    CustomLog ${APACHE_LOG_DIR}/help.suar.services_access.log combined
</VirtualHost>

7. Enable Virtual Hosts

Enable the newly created virtual host files:

sudo a2ensite suar.services.conf
sudo a2ensite cv.suar.services.conf
sudo a2ensite help.suar.services.conf

8. Obtain SSL Certificates with Let’s Encrypt

Use Certbot to obtain SSL certificates for all three domains:

sudo certbot --apache -d suar.services -d cv.suar.services -d help.suar.services --email info@suar.services

Certbot will automatically:

  • Obtain the certificates.
  • Add HTTPS configurations to your virtual host files.
  • Enable HTTP-to-HTTPS redirection (optional).

9. Test Configuration

Verify your Apache configuration is correct:

sudo apache2ctl configtest

Restart Apache to apply changes:

sudo systemctl restart apache2

10. Test the Websites

  • Visit http://suar.services and https://suar.services.
  • Visit http://cv.suar.services and https://cv.suar.services.
  • Visit http://help.suar.services and https://help.suar.services.

11. Auto-Renew SSL Certificates

Certbot sets up automatic renewal. Test it with:

sudo certbot renew --dry-run

This ensures your SSL certificates are renewed before expiration.


Comments

Leave a Reply

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