Questions about Apache Web Server Directories and IP Addresses

Posted September 10, 2019 2.1k views


When you setup an Apache Web Server, what is the default directory that can be accessed with just the IP Address and how do you manage/change the default?

For a scenario when there are multiple websites on a single Web Server (which is managed by CPanel) one should prefer a dedicated IP or prefer a shared IP for allowing each of those websites to seperate Domain Names? And how would you manage the assigning of the each website’s DNS records?

Thank you!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You would need to setup whats known as Virtual Hosts in your Apache config. There is a good walk through here for Ubuntu 16.04, The process is fairly similar in every distribution.

In the Create the First Virtual Host File section shows you how to set this up in the file /etc/apache2/sites-available/default.conf as shown below

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

This example accepts all traffic for port 80 and sends it to /var/www/html. This includes all unassigned IP addresses and domains.

To add an assigned domain you would create a file /etc/apache2/sites-available/ and enter the below configuration.

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Repeating this for each domain/ip and adjusting the values in red.

You will following the remaining steps in the above link to enable these configurations.

by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.