Questions about Apache Web Server Directories and IP Addresses

September 10, 2019 78 views
Apache

Hey.

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!

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
</VirtualHost>

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/domain.com.conf and enter the below configuration.

<VirtualHost *:80>
    ServerAdmin admin@domain.com
    ServerName domain.com
    ServerAlias www.example.com
    DocumentRoot /var/www/domain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

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.
Have another answer? Share your knowledge.