2.4 httpd three ways to build a virtual web host

Source: Internet
Author: User

############################# #构建Web虚拟主 ##################################
The HTTPD supported virtual host types include the following three kinds.
Domain-based: A different domain name is used for each virtual host, but it is the same for the IP address.
Based on IP address: Different domain names are used for each virtual host, and the respective IP addresses are not the same.
Port-based: Use different TCP port numbers instead of domain names, IP addresses to differentiate different site content.
`

################################ #基于IP地址的虚拟主机 #########################
<br/>####开启虚拟机主机功能模块####<br/>
Vi/usr/local/httpd/conf/httpd.conf
#Listen localhost:80 #必须禁用
#Virtual hosts
Include conf/extra/httpd-vhosts.conf #这行前面的 # Remove vhosts module in effect
`
cd/usr/local/httpd/conf/extra/
VI httpd-vhosts.conf

<br/>######为了直接显示源代码,在后面添加ab、aa为主页文件##<br/>vi /usr/local/httpd/httpd.conf <br/>**&lt;IfModule dir_module&gt;**<br/>DirectoryIndex index.html ab.html aa.html<br/>**&lt;/IfModule&gt;**<br/>
# # # # #默认的实列 # # # #
#<virtualhost :80>
#ServerAdmin [email protected]
#DocumentRoot "/usr/local/httpd/docs/dummy-host.example.com"
#ServerName dummy-host.example.com
#ServerAlias www.dummy-host.example.com
#ErrorLog "Logs/dummy-host.example.com-error_log"
#CustomLog "Logs/dummy-host.example.com-access_log" common
#</virtualhost>
`
#<virtualhost
:80>

#ServerAdmin [email protected]
#DocumentRoot "/usr/local/httpd/docs/dummy-host2.example.com"
#ServerName dummy-host2.example.com
#ErrorLog "Logs/dummy-host2.example.com-error_log"
#CustomLog "Logs/dummy-host2.example.com-access_log" common
#</virtualhost>
`

########## #基于IP地址的虚拟主机 ##########
Listen 192.168.10.11:80 # # # #必须要开启监听

<virtualhost 192.168.10.11:80>
ServerAdmin [email protected] # # # #设置http服务器管理员的E-mail address, you can contact the webmaster of the Web site by e-mail address
documentroot/opt/aa/# # # #设置网站跟目录, the path that the Web page stores in the system
ServerName www.aa.com # # # #设置网站的完整主机名, i.e. (hostname + domain name)
Errorlog Logs/aa.com-error_log # # # #错误日志存放路径
Customlog Logs/aa.com-access_log Common # # # #访问日志文件路劲
</VirtualHost>

<directory "/opt/aa" ># # # #区域配置的根目录 is the/OPT/AA directory
Options Indexes FollowSymLinks # # #基础配置
allowoverride all ##### #允许所有主机
Require all granted # # # #允许所有主机访问
</Directory>

Listen 192.168.20.11:80
<virtualhost 192.168.20.11:80>
ServerAdmin [email protected]
documentroot/opt/ab/
ServerName www.ab.com
Errorlog Logs/ab.com-error_log
Customlog Logs/ab.com-access_log Common
</VirtualHost>

<directory "/opt/ab" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<br/>######验证#####<br/>service httpd restart<br/>登录客户端的浏览器测试!!!<br/>测试2个地址: <br/>1、192.168.10.11<br/>2、192.168.20.11<br/>
################################## #基于端口号 ################################
Listen 192.168.10.11:80

<virtualhost 192.168.10.11:80>
ServerAdmin [email protected]
documentroot/opt/aa/
ServerName www.aa.com
Errorlog Logs/aa.com-error_log
Customlog Logs/aa.com-access_log Common
</VirtualHost>

<directory "/opt/aa" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Listen 192.168.10.11:8080
<virtualhost 192.168.10.11:8080>
ServerAdmin [email protected]
documentroot/opt/ab/
ServerName www.ab.com
Errorlog Logs/ab.com-error_log
Customlog Logs/ab.com-access_log Common
</VirtualHost>
<directory "/opt/ab" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
`
##### #验证 #####
Service httpd Restart
Login to the client's browser test!!!
Test 2 addresses:
1, 192.168.10.11:80
2, 192.168.10.11:8080

########################## #基于域名的虚拟主机 ###################
Listen 192.168.10.74:80
`
*<virtualhost :80>
ServerAdmin [email protected]
documentroot/opt/aa/
ServerName www.aa.com
Errorlog Logs/aa.com-error_log
Customlog Logs/aa.com-access_log Common
</virtualhost>**

<directory "/opt/aa" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

*<virtualhost :80>
ServerAdmin [email protected]
documentroot/opt/ab/
ServerName www.ab.com
Errorlog Logs/ab.com-error_log
Customlog Logs/ab.com-access_log Common
</virtualhost>**

<directory "/opt/ab" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

##### #验证 #####
Service httpd Restart
Login to the client's browser test!!
####
The client needs to add the domain name resolution in the Hosts file:

192.168.10.11 www.aa.com
192.168.10.11 www.ab.com

####
Test 2 addresses:
1, www.aa.com
2, www.ab.com

2.4 httpd three ways to build a virtual web host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.