Configuring Virtual Hosts on Debian 11 with Apache and OpenSSL

SSH Keys Using Putty Image

Configure Domain Names and Modify Hosts File

Configure Domain Names

Ensure that the domain names of your sites are configured to point to your server's IP address. You can do this by modifying the DNS records of your domain names.

Modify hosts file on Windows

In C:\Windows\System32\drivers\etc\hosts, enter your server's IP address followed by the domain name. For example:

Open the hosts file in a text editor with administrative privileges (e.g., Notepad++ or Notepad as Administrator).

Add an entry in the following format:

192.168.1.100 example.com www.example.com

Replace 192.168.1.100 with your server's actual IP address, and example.com with your domain name. You can add multiple domain names if needed, each on a new line.

Save the file after making changes.

Note: Modifying the hosts file allows you to test your site on your local machine before DNS changes propagate globally.

Configuration Steps

  1. Install Apache and OpenSSL
  2. Ensure your system is up to date, then install Apache and OpenSSL if not already installed:

    sudo apt update
    sudo apt install apache2 openssl
  3. Generate SSL Keys with OpenSSL
  4. Use OpenSSL to generate a private key and a self-signed certificate (or obtain a valid SSL certificate if available):

    sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
  5. Enable Necessary Apache Modules
  6. Ensure required Apache modules are enabled:

    sudo a2enmod ssl
    sudo a2enmod headers
    sudo systemctl restart apache2
  7. Configure Virtual Hosts
  8. Create configuration files for your virtual hosts in /etc/apache2/sites-available/.

    Restart Apache to apply the changes:

    sudo systemctl restart apache2

Additional Notes:

How to Install LAMP Apache, MySQL, PHP on Debian 11 ? Install and Configure Nagios on Debian 11 Install PureFTPd and Set Up MySQL Install Certbot Connect with SSH Keys Using Putty