Define Subdomain on Apache Server using FritzBox
In this article, we will discuss how to define a subdomain for your Apache server by configuring your FritzBox. This process involves setting up port forwarding on the FritzBox and configuring the Apache virtual host file. By the end of this article, you will have a clear understanding of how to accomplish this task.
Prerequisites
To follow along with this guide, you will need the following:
- An Apache server
- A FritzBox router
- Access to the FritzBox web interface
- Access to the Apache configuration files
Setting up Port Forwarding on the FritzBox
The first step is to set up port forwarding on the FritzBox. Port forwarding is necessary to allow incoming traffic destined for a specific port to be forwarded to a specific device on your local network. In this case, we will forward traffic destined for ports 80 and 443 (HTTP and HTTPS) to our Apache server.
<1> Login to the FritzBox web interface.
<2> Navigate to "Internet" > "Permit Access".
<3> Under "Port Forwarding", click "Add Device".
<4> Select the device running the Apache server.
<5> Enter a name for the port forwarding rule, such as "Apache HTTP".
<6> For the "Protocol" field, select "TCP".
<7> For the "Public Ports" field, enter "80,443".
<8> For the "Private Port" field, enter "80,443".
<9> For the "IP Address" field, enter the local IP address of the Apache server.
<10> Click "OK" to save the rule.
Configuring the Apache Virtual Host File
The next step is to configure the Apache virtual host file. A virtual host allows you to define multiple domains and subdomains on a single Apache server. In this case, we will define a subdomain for our Apache server.
<1> Open the Apache virtual host file using a text editor.
<2> Add the following code at the end of the file, replacing "subdomain" and "yourdomain.com" with your desired values:
ServerName subdomain.yourdomain.com
ServerAlias www.subdomain.yourdomain.com
DocumentRoot /path/to/subdomain/docs
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/subdomain.error.log
CustomLog ${APACHE_LOG_DIR}/subdomain.access.log combined
<3> Save the changes and close the text editor.
<4> Test the new virtual host configuration by running the following command:
sudo apachectl configtest
<5> If the configuration test is successful, restart the Apache server to apply the changes:
sudo systemctl restart apache2
Verifying the Subdomain
The final step is to verify that the subdomain is working as expected. To test this, open a web browser and navigate to the subdomain. If everything has been set up correctly, you should see the contents of the subdomain DocumentRoot directory.
- In this article, we discussed how to define a subdomain for your Apache server by configuring your FritzBox.
- We learned how to set up port forwarding on the FritzBox, which allows incoming traffic destined for a specific port to be forwarded to a specific device on your local network.
- We also learned how to configure the Apache virtual host file, which allows you to define multiple domains and subdomains on a single Apache server.