Use Virtual Host (In Virtual Name) In Apache

Use Virtual Host (In Virtual Name) In Apache

The user uses a virtual name for the purpose of running different hostnames on a server. There are two types of virtual names that can be used in Apache: name-based virtual hosts and IP-based virtual hosts.

Using a virtual name by relying on the name has the advantage that you only need to use an IP address for all names.

It is important to declare all the names you want to use with Apache in the DNS server first . If you only declare the names differently in httpd.conf (or apache.conf), but the DNS server does not have information of the name, the user will not see your site. The disadvantage of using a virtual name based on the name is that you can not use SSL for all names, because SSL requires that each name have its own IP address while using a name based virtual name. You only have one IP for different names.

Specific examples:

vnlinux.org whose address is 24,153,136,146 . Why do you know? Just type host vnlinux.org You will see the answer below:

rhs @ gw rhs $ host vnlinux.org
vnlinux.org has address 24.153.136.146

Every time you visit the vnlinux.org website, the user can type http://www.vnlinux.org or http://vnlinux.org Both addresses are different but the content is the same. Why so? If you type host www.vnlinux.org You will see the answer

rhs @ gw rhs $ host www.vnlinux.org
www.linux.org is an alias for vnlinux.org.

The reason is because I have declared in the DNS record, www.vnlinux.org will be an alias (also known as CNAME when setting up the DNS server) vnlinux.org Below are the rows taken from the db.vnlinux.org file of the DNS server

vnlinux.org. IN A 24.153.136.146
www.vnlinux.org. IN CNAME vnlinux.org.

In httpd.conf (or apache.conf), I declare ServerName www.vnlinux.org
The above example simply explains how to use the CNAME for the site.

Next I will explain how to configure dns and apache for using name-based virtual hosts.
The example above you have also seen www.vnlinux.org there is IP 24,153,136,146 I also have the last site with the same IP vnlinux.org using a virtual name based on the name.
howto.vnlinux.org
i18n.vnlinux.org
1 AzSoft_watermark_big.png AzSoft_watermark_small.png cong-nghe? p = 1 en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.quantrimang.com label: Some Text link_original.txt link .txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2-1.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb tim-hieu-excel-2016-200.jpg title_vn.txt tmp02 .html tmp03.html tmp2.html tmpdesc2.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.quantrimang.com www.mailenable. com www.microsoft.com www.securityfocus.com
Below is the result of the host command for the names above.

rhs @ gw rhs $ host howto.vnlinux.org
howto.vnlinux.org has address 24.153.136.146

rhs @ gw rhs $ host i18n.vnlinux.org
i18n.vnlinux.org has address 24.153.136.146

rhs @ gw rhs $ host xn--dchthut-5p4c4j.vnlinux.org
xn--dchthut-5p4c4j.vnlinux.org has address 24.153.136.146

1 AzSoft_watermark_small.png cong-nghe? P = 1 en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.quantrimang.com label: Some Text link_original.txt link.txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2-1.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb tim-hieu-excel-2016-200.jpg title_vn.txt tmp02.html tmp03.html tmp2.html tmpdesc2.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.quantrimang.com www.mailenable.com www.microsoft.com. com www.securityfocus.com xn - dchthut-5p4c4j is a punycode format for translation
Read more about punycode by clicking here http://search.yahoo.com/search?ei=UTF-8&fr=sfp&p=punycode

Information declared for DNS Please restart the DNS server

howto.vnlinux.org. IN A 24.153.136.146
i18n.vnlinux.org. IN A 24.153.136.146
xn--dchthut-5p4c4j.vnlinux.org. IN A 24.153.136.146

Buckels7 Thicks777777777777777777777777777777777777777777777777 Flesswidd) Flickwidelswidels Flush Fliecher kselskawelskawelswidels Flannelskawelswidels Flannelskawilswid

NameVirtualHost 24.153.136.146:80
(VirtualHost 24.153.136.146:80)
ServerAdmin me@here.com
DocumentRoot / Where / Where / Files / News / Locations / In / htdocs
ServerName www.vnlinux.org
ErrorLog logs / VietLUG_error_log
CustomLog logs / VietLUG_access_log common
DirectoryIndex index.html
RewriteEngine
RewriteCond% {REQUEST_METHOD} ^ {TRACE | TRACK}
RewriteRule. .. - [F]
(VirtualHost)

Replace () with & lt; & gt; before and after the word VirtualHost. Do not forget to top up the top.

(VirtualHost 24.153.136.146:80)
ServerAdmin me@here.com
DocumentRoot / Where / Where / Files / News / Locations / In / htdocs
ServerName xn--dchthut-5p4c4j.vnlinux.org
ErrorLog logs / dichthuat_error_log
CustomLog logs / dichthuat_access_log common
DirectoryIndex index.html
RewriteEngine
RewriteCond% {REQUEST_METHOD} ^ {TRACE | TRACK}
RewriteRule. .. - [F]
(VirtualHost)

Replace () with & lt; & gt; before and after the word VirtualHost. Do not forget to top up the top.

Just like howto and i18n. After declaring the above rows, you must restart apache.

Note: These lines are the basic declarations in httpd.conf. Depending on the need to serve the site you may very well need to add the values ​​as you like

If you have full DNS and apache declarations and still do not see the virtual names working, you probably have to wait within a day (or sooner or later) for the DNS records to contain the information you just made. up to date.

Want to check immediately whether the virtual names have been set correctly yet you can type httpd -S (or apache -S)

This tutorial shows how to set up dns and apache as needed for using a name-based virtual host. You can read more about Apache documentation at with instructions on how to use IP-based virtual hosts and more complex examples