This topic describes how to modify Apache configuration files to point multiple domain
names to different websites deployed on a simple application server. Then, you can
use the domain names to access the websites over HTTP.
Background information
In the examples, the following resources are used:
- Server: a simple application server created from the LAMP 7.4 application image.
- Two test websites:
test01
and test02
.
- Two test domain names:
test01.example.com
and test02.example.com
.
After you complete the configurations described in this topic, you can perform the
following operations:
- Use
test01.example.com
to access the test01
website.
- Use
test02.example.com
to access the test02
website.
In actual operations, you must replace these example resources with your own resources.
Step 1: Create test websites
If the code of your multiple websites is already stored in the root directory of websites
on the server, skip this step.
- Connect to the LAMP server.
- Run the following command to switch to the
root
user:
- Run the following command to go to the root directory of websites:
The root directory of websites varies based on the LAMP versions in the LAMP application
images used on simple application servers.
- If the LAMP 7.4 application image is used, the root directory of websites is /data/wwwroot/default.
- If the LAMP 6.1.0 application image is used, the root directory of websites is /home/www/htdocs.
In this example, the LAMP 7.4 application image is used. Therefore, run the following
command to go to the root directory of websites:
cd /data/wwwroot/default
- Run the following commands in sequence to create two subdirectories.
The subdirectories are used to store the code of websites.
mkdir test01
mkdir test02
- Go to the test01 subdirectory, and create and edit the index.html file.
- Run the following command to go to the test01 subdirectory:
cd /data/wwwroot/default/test01/
- Run the following command to create the index.html file:
- Press the I key to enter the edit mode and add the following test information to the file:
- Press the Esc key, enter
:wq
, and then press the Enter key to save and close the file.
- Go to the test02 subdirectory, and create and edit the index.html file.
- Run the following command to go to the test02 subdirectory:
cd /data/wwwroot/default/test02/
- Run the following command to create the index.html file:
- Press the I key to enter the edit mode and add the following test information to the file:
- Press the Esc key, enter
:wq
, and then press the Enter key to save and close the file.
Step 2: Modify Apache configuration files
- Modify the httpd.conf configuration file.
- Run the following command to open the httpd.conf file:
vi /usr/local/apache/conf/httpd.conf
- Press the I key to enter the edit mode, and modify configurations.
Find the following configurations:
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Delete
#
from the beginning of the
#Include conf/extra/httpd-vhosts.conf
line.
The following figure shows the modified line.

- Press the Esc key, enter
:wq
, and then press the Enter key to save and close the file.
- Modify the httpd-vhosts.conf file.
- Run the following command to open the httpd-vhosts.conf file:
vi /usr/local/apache/conf/extra/httpd-vhosts.conf
- Press the I key to enter the edit mode, and modify configurations.
You must comment out the default configurations that are enclosed by the
<VirtualHost *:80></VirtualHost>
tags in the file and manually add multiple domain names.
In this example, perform the following operations:
- Comment out the default configurations, as shown in the following figure.

- Add the following configurations to the end of the file:
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/default/test01"
ServerName test01.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/default/test02"
ServerName test02.example.com
</VirtualHost>
You can configure the following parameters based on your needs:
DocumentRoot
: the website directory. Specify this parameter in the format of DocumentRoot "<website directory>"
.
ServerName
: the domain name. Specify this parameter in the format of ServerName <domain name>
.
- Press the Esc key, enter
:wq
, and then press the Enter key to save and close the file.
- Run the following command to restart Apache:
/usr/local/apache/bin/apachectl restart
Step 3: Bind domain names
For the two test domain names used in this example, you must add the mappings between
these domain names and the public IP address of the LAMP server to the hosts file
on your Windows computer.
Note If you use actual domain names when you configure the websites, skip this step. You
must bind multiple domain names to the LAMP server. For more information, see
Bind and resolve domain names. After domain names are bound, you can use the domain names to access the corresponding
websites.
- Go to the C:\Windows\System32\drivers\etc directory.
- Copy the hosts file for backup.
Retain the hosts - copy file, which can be used to restore the hosts file to the initial state after the test is complete.
- Modify the hosts file.
Append the following information to the end of the file:
<Public IP address of the simple application server> test01.example.com
<Public IP address of the simple application server> test02.example.com
- Go back to the Windows desktop and press Win+R.
- In the Run dialog box, enter
cmd
and click OK.
- On the command line, run the following command to make the new configurations of the
hosts file immediately take effect:
Step 4: Access the website by using the bound domain names
Use a browser to access the test websites on your Windows computer.
- Use
test01.example.com
to access the test01
website, as shown in the following figure. 
- Use
test02.example.com
to access the test02
website, as shown in the following figure. 