2.4 httpd 构建虚拟Web主机的三种方式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.4 httpd 构建虚拟Web主机的三种方式相关的知识,希望对你有一定的参考价值。
##############################构建Web虚拟主##################################
httpd支持的虚拟主机类型包括以下三种。
基于域名:为每个虚拟主机使用不同的域名,但是其对于的ip地址是相同的。
基于IP地址:为每个虚拟主机使用不同的域名,且各自对于的ip地址也不相同。
基于端口:不使用域名,IP地址来区分不同的站点内容,而是使用了不同的TCP端口号。
`
#################################基于IP地址的虚拟主机#########################<br/>####开启虚拟机主机功能模块####<br/>
vi /usr/local/httpd/conf/httpd.conf
#Listen localhost:80 #必须禁用
#Virtual hosts
Include conf/extra/httpd-vhosts.conf #这行前面的#去掉 vhosts模块生效
`
cd /usr/local/httpd/conf/extra/
vi httpd-vhosts.conf
<br/>######为了直接显示源代码,在后面添加ab、aa为主页文件##<br/>vi /usr/local/httpd/httpd.conf <br/>**<IfModule dir_module>**<br/>DirectoryIndex index.html ab.html aa.html<br/>**</IfModule>**<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地址,可以通过E-mail地址联系WEB站点的管理员
DocumentRoot /opt/aa/ ####设置网站跟目录,即网页在系统中存放的路径
ServerName www.aa.com ####设置网站的完整主机名,即(主机名+域名)
ErrorLog logs/aa.com-error_log ####错误日志存放路径
CustomLog logs/aa.com-access_log common ####访问日志文件路劲
</VirtualHost>
<Directory "/opt/aa"> ####区域配置的根目录 是/opt/aa目录
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
登录客户端的浏览器测试!!!
测试2个地址:
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
登录客户端的浏览器测试!!
####
客户端需要在hosts文件添加域名解析:
192.168.10.11 www.aa.com
192.168.10.11 www.ab.com
####
测试2个地址:
1、www.aa.com
2、www.ab.com
以上是关于2.4 httpd 构建虚拟Web主机的三种方式的主要内容,如果未能解决你的问题,请参考以下文章