How to Set Up Linux Apache Server
Page 19: Set Up Your First Virtual Host (Part 2)
Now, we need to add the Virtual Account Information to the Apache Configuration File (httpd.conf). The httpd.conf file can be found in /etc/http/conf directory and can be opened and edited by any text editor.
The httpd.conf file is a very long file. The file is grouped into three sections:
- Section 1: Global Enviroment
- Section 2: Main Server Configuration
- Section 3: Virtual Hosts
If you are not very familiar with the file at this moment, don't change everything in Section 1 and Section 2. The default setting should be okay. What we need to do is to add a few lines in Section 3.
The following is only a very simple example in order that you can run your first virtual hosting. Please follow:
- Open httpd.conf with a text editor.
- Find the text " ### Section 3: Virtual Hosts"
- There are some examples show you how to add Virtual Host
- Find the following two lines:
# NameVirtualHost 12.34.56.78:80
# NameVirtualHost 12.34.56.78 - We will add the first Virtual Host behind these two lines
- Add the following line:
NameVirtualHost 192.168.1.3 - To add the first Virtual Host, add the following lines:
<VirtualHost 192.168.1.3>
ServerName yourdomain.com
DocumentRoot /var/www/html/yourdomain/public_html
</VirtualHost> - If you have other Virtual Host (e.g. otherdomain.com) that need to add later, simply add the following lines after the first Virtual Host:
<VirtualHost 192.168.1.3>
ServerName otherdomain.com
DocumentRoot /var/www/html/otherdomain/public_html
</VirtualHost> - You must RESTART your computer or Apache Server for the new records in effect.
- Restart your Apache Server
- Open a browser in any computer connected with the Internet and browse.
- The homepage should be displayed. If not, please check the setting again.
NOTE:
The above is a very simple example, you can add more directive between the <VirtualHost>.
You may refer to Apache documentation for more details.
This is the end of this Setting Up Linux Apache Web Server tutorial series.