Debian Apache2 Host: Accessing Virtual Host Pages from Another Device Network
In this article, we will discuss how to configure Apache2 to run on a Debian host, creating three virtual hosts and accessing their pages from another device on the network. We will cover the key concepts and provide detailed instructions using subtitles, paragraphs, and code blocks as needed.
Prerequisites
Before we begin, make sure you have the following:
- A Debian-based system with Apache2 installed
- Three domains or subdomains to use for the virtual hosts
- Access to the system via SSH or a terminal
Step 1: Configuring the Virtual Hosts
Begin by creating the necessary configuration files for the virtual hosts. In this example, we will use the domains vhost1.example.com, vhost2.example.com, and vhost3.example.com.
sudo nano /etc/apache2/sites-available/vhost1.example.com.conf
sudo nano /etc/apache2/sites-available/vhost2.example.com.conf
sudo nano /etc/apache2/sites-available/vhost3.example.com.conf
Add the following configuration to each file, replacing the domain name as necessary:
<VirtualHost *:80>
ServerName vhost1.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/vhost1.example.com/public_html
<Directory /var/www/vhost1.example.com/public_html>
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the virtual host configurations and disable the default configuration:
sudo a2ensite vhost1.example.com.conf
sudo a2ensite vhost2.example.com.conf
sudo a2ensite vhost3.example.com.conf
sudo a2dissite 000-default.conf
Step 2: Creating the Virtual Host Pages
Next, create the necessary directories and files for the virtual host pages:
sudo mkdir /var/www/vhost1.example.com
sudo mkdir /var/www/vhost2.example.com
sudo mkdir /var/www/vhost3.example.com
sudo chown -R $USER:$USER /var/www/vhost1.example.com
sudo chown -R $USER:$USER /var/www/vhost2.example.com
sudo chown -R $USER:$USER /var/www/vhost3.example.com
sudo nano /var/www/vhost1.example.com/public_html/index.html
sudo nano /var/www/vhost2.example.com/public_html/index.html
sudo nano /var/www/vhost3.example.com/public_html/index.html
Add some basic content to each file, save, and exit.
Step 3: Restarting Apache2
Finally, restart Apache2 to apply the changes:
sudo systemctl restart apache2
Accessing the Virtual Host Pages from Another Device
To access the virtual host pages from another device on the network, you will need to know the IP address of the Debian host. You can find this by running the following command:
ip a
Take note of the IP address, and then, from another device on the same network, open a web browser and navigate to http://<IP\_ADDRESS>/, replacing <IP\_ADDRESS> with the actual IP address of the Debian host.
In this article, we have discussed how to configure Apache2 to run on a Debian host, creating three virtual hosts and accessing their pages from another device on the network. By following the steps outlined above, you should be able to successfully set up and access your own virtual hosts.