Apache中,同一IP使用多域名对应多个网站的方法

首先dns中确定有相应的A记录,
abc  IN A   211.154.2.5
mail IN A   211.154.2.5

这个讲的是在windows下面配置apache虚拟主机:
一、配置虚拟主机需要3个文件
1.Apache/conf/httpd.conf
2.Apache/conf/extra/httpd-vhosts.conf (这个地版本的apache可能没有,可自己创建,也可以不要此文件,
而将配置直接写在httpd.conf里面,写在extra/httpd-vhosts.conf只是为了管理方便,不让httpd.conf文件
内容很多而已)
3.C:\WINDOWS\system32\drivers\etc\hosts
①httpd.conf 找到VirtualHost example,在后面引入httpd-vhosts.conf文件:
Include conf/extra/httpd-vhosts.conf
这个句话,高版本的apache里面已经写有了,只需吧Include前面的#号去掉就OK
②httpd-vhosts.conf配置文件的内容如下:
#
# DocumentRoot 是网站文件存放的根目录
# ServerName 是网站域名, 需要跟 DNS 指向的域名一致
#

#########################################################################################

# http://www.PHPnow.org
# filename: httpd-vhosts.conf

<Directory ../vhosts>
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost *

<VirtualHost *>
    DocumentRoot ../htdocs
    ServerName default:80
    ErrorLog logs/default-error_log
</VirtualHost>

#<VirtualHost *>
#    ServerAdmin benrenxw522@sina.com
#    DocumentRoot "D:/htdocs/lxcms"
#    ServerName cms.weixinyixia.com:80
#    ServerAlias cms.weixinyixia.com
#    ErrorLog logs/cms.weixinyixia.com-error_log
#</VirtualHost>

=======================================================以下只是参考其他方式~=======================================================================

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
 DocumentRoot /www/deerol_com
 ServerName www.deerol.com

 # Other directives here
 #配置域名的目录访问权限
 <Directory "/www/deerol_com">
      Options Indexes FollowSymLinks
      allow from all
 </Directory>
</VirtualHost>

<VirtualHost *:80>
 DocumentRoot /www/163_com
 ServerName www.163.com

 # Other directives here
 #配置域名的目录访问权限
 <Directory "/www/deerol_com">
      Options Indexes FollowSymLinks
      allow from all
 </Directory>
</VirtualHost> 

以上设置中第一项(即ServerName www.deerol.com)是默认选项。若用户访问所指定的域名不符合所有条目时采用默认项,即指向www.deerol.com。

在配置时可能遇到的场景:

1.使用域名加端口访问

如果需要带端口访问(这种情况很少,一般会在测试时用到)如:www.domain.com:8081 这时在配置<VirtaulHost> 后,还需要添加对该端口的监听Listen 8081


2.如果服务器上除了Apache服务外还装了IIS(运行asp,asp.net程序),Tomcat(运行java,jsp程序)服务该如何配置?

一般的我们会把Apache默认为80端口,IIS可以设置为81端口,Tomcat设置为8080端口。假设有一jsp程序,在服务器本地配置时我们可以通过http://localhost:8080/document访问。那如何配置通过域名访问到该地址呢?

<VirtualHost *:80>
 ProxyPreserveHost On
 ServerName yourdomain.com
 DirectoryIndex index.jsp
 ProxyPass / http://localhost:8080/KBoom/
 ProxyPassReverse / http://localhost:8080/KBoom/
</VirtualHost>  

这里我们注意到使用了代理访问。首先开启代理支持ProxyPreserveHost On,然后再配置正向代理和反向代理 ProxyPass /  http://localhost:8080/KBoom (kboom为虚拟目录) 

<摘自:http://blog.sina.com.cn/s/blog_75ad10100101m5q6.html&http://blog.csdn.net/zhanglei5415/article/details/6821066>

上一篇:微信小程序前置课程:Flex 布局教程(一):语法篇


下一篇:js面向对象学习笔记(五):tab切换