Apache virtual host configuration and generic domain name resolution implementation code

  • 2020-05-06 12:00:15
  • OfStack

Virtual host configuration
Configure
for the virtual host based on the IP address 80
Listen DocumentRoot www/jb51
ServerName www. jb51. net
DocumentRoot www/jb512
ServerName www. jb512. org
Configure
based on IP and multi-port virtual hosts
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080 DocumentRoot www/
jb51-80 ServerName www. jb51. net
DocumentRoot www/
jb51-8080 ServerName www. jb51. net
DocumentRoot www/
example2-80 ServerName www. jb51. org
DocumentRoot www/
example2-8080 ServerName www. example2. org
Domain-based hosting configuration on a server with a single IP address:
# Ensure that Apache listens on port 80
80
Listen Listen for virtual host requests on IP addresses

NameVirtualHost * : 80 DocumentRoot www/jb51
ServerName www. jb51. net
ServerAlias jb51. net. *. jb51. net
# Other directives here
DocumentRoot www/example2
ServerName www. example2. org
# Other directives here
Configure a domain-based virtual host on multiple servers with IP addresses:
80
Listen This is the "main" server running on 172.20.30.40
ServerName server. domain. com
DocumentRoot www/mainserver
# This is the other address
NameVirtualHost 172.20.30.50
DocumentRoot www/jb51
ServerName www. jb51. net
# Other directives here...
DocumentRoot www/example2
ServerName www. example2. org
# Other directives here...
Run different sites on different ports:
Configure a domain-based virtual host on a multi-port based server.
80
Listen 8080
Listen
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080 ServerName www. jb51. net
DocumentRoot www/
domain - 80 ServerName www. jb51. net
DocumentRoot www/
domain - 8080 ServerName www. example2. org
DocumentRoot www/
otherdomain - 80 ServerName www. example2. org
DocumentRoot www/
otherdomain - 8080 Configuration of hybrid virtual hosts based on domain name and IP:
80
Listen NameVirtualHost 172.20.30.40
DocumentRoot www/jb51
ServerName www. jb51. net
DocumentRoot www/example2
ServerName www. example2. org
DocumentRoot www/example3
ServerName www. example3. net

Add a virtual host configuration (as follows) :

DocumentRoot d: / web jb51 # website absolute path
root directory ServerName www. jb51. net
# website domain name ServerAlias *. Es272en51.net # website generic domain name

APACHE generic domain configuration reference

NameVirtualHost 192.168.0.110

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/workplace/"
ServerName www.workplace.com
< Directory "E:/InterRoot/workplace/" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/busymouse_test/"
ServerName www.test.com
< Directory "E:/InterRoot/busymouse_test/" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/iptv_for_browser/auth"
ServerName auth.billing.com
ServerAlias auth.billing.com *.auth.billing.com

ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:/InterRoot/iptv_for_browser/auth" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/iptv_for_browser/api"
ServerName voiz.billing.com
ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:/InterRoot/iptv_for_browser/api" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/iptv_for_browser/user"
ServerName user.billing.com
ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:/InterRoot/iptv_for_browser/user" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/iptv_for_browser/center"
ServerName center.billing.com
ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:/InterRoot/iptv_for_browser/center" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/iptv_for_browser/img"
ServerName img.billing.com
ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:/InterRoot/iptv_for_browser/img" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:/InterRoot/iptv_for_browser/log"
ServerName log.billing.com
ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:/InterRoot/iptv_for_browser/log" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

< VirtualHost 192.168.0.110:80 >
DocumentRoot "E:\InterRoot\billing_new\front"
ServerName admin.billing.com
ErrorLog "E:/InterRoot/iptv_for_browser/serverlog/apache.log"
< Directory "E:\InterRoot\billing_new\front" >
AllowOverride FileInfo
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

Related articles: