Chinaunix首页 | 论坛 | 博客
  • 博客访问: 70342
  • 博文数量: 24
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 245
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-25 18:16
文章分类

全部博文(24)

文章存档

2008年(21)

2007年(3)

我的朋友
最近访客

分类: 系统运维

2008-03-11 18:38:21

虚拟主机(Virtual Host)的设置

  作为员,若你只有一个IP地址,却有好几个域名,又要求访问每个域名都要看到不同的内容,那怎么办?总不至于为每个域名都配上一台服务器吧。这就要采用虚拟主机(Virtual Host)技术,幸好Apache就支持这种功能。虚拟主机有两种方式:IP-Based(基于IP式)、Name-based(基于域名式)。IP-Based指的是一个域名对应一个IP地址,而Name-based指的是多个域名对应一个IP地址。

  虚拟主机的设置并不复杂,只要在httpd.conf文件中加入相应的命令就行。

  下面是一个Name-based(基于域名式)虚拟主机的httpd.conf例子(编者注:因篇幅原因,我们这只给出了相关部分,全文见)。IP为:192.168.188.20,两个域名分别是long.com.cn、short.com.cn。

httpd.conf:

NameVirtualHost 192.168.188.20

ServerAdmin webmaster@long.com
ServerName
DocumentRoot /home/httpd/long/html 

ErrorLog logs/error_log
TransferLog logs/access_log


ServerAdmin webmaster@short.com
ServerName
DocumentRoot /home/httpd/short/html
ErrorLog logs/short.com-error_log
TransferLog logs/short.com-access_log


  NameVirtualHost命令指定在哪个IP上设置虚拟主机

  在VirtualHost命令中进行各个主机的具体设置。

  ServerAdmin命令是设定当WWW Server执行有问题时,会将ServerAdmin所设置的E-mail传送到浏览器,让使用者用该E-mail与员联系。
 
 
(一).ProxyPass 指令

说明: 将一个远端服务器映射到本地服务器的URL空间中
语法: ProxyPass [路径] !|url
上下文: 服务器配置, 虚拟主机
状态: Extension
模块: mod_proxy

指令对于您不想对某个子目录进行反向代理时很有用。比如说:

ProxyPass /mirror/foo/i !
ProxyPass /mirror/foo

将会代理除对/mirror/foo/i请求之外的所有对 foo.com 的/mirror/foo请求。

注意:顺序很重要,您需要把特例情况放在一般代理通过指令
当在配置段中使用时,第一个参数会被忽略而是采用由指令指定的本地目录。

如果您需要一个更加灵活的反向代理配置,请参见使用[P]标记的RewriteRule指令。

------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
(二).ProxyPassReverse 指令

说明: 调整由反向代理服务器发送的HTTP回应头中的URL
语法: ProxyPassReverse [路径] url
上下文: 服务器配置, 虚拟主机
状态: Extension
模块: mod_proxy

此指令使 Apache 调整HTTP重定向回应中Location, Content-Location和URI头里的URL。 HTTP redirect responses. This is essential when Apache is used as a reverse proxy to avoid by-passing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.

路径是本地虚拟路径的名称。
url远端服务器的部分URL。与ProxyPass指令中的使用方法相同。

示例:
假定本地服务器拥有地址;那么

ProxyPass /mirror/foo/
ProxyPassReverse /mirror/foo/

will not only cause a local request for the to be internally converted into a proxy request to (the functionality ProxyPass provides here). It also takes care of redirects the server foo.com sends: when bar is redirected by him to quux Apache adjusts this to mirror/foo/quux before forwarding the HTTP redirect response to the client. Note that the hostname used for constructing the URL is chosen in respect to the setting of the UseCanonicalName directive.

Note that this ProxyPassReverse directive can also be used in conjunction with the proxy pass-through feature ("RewriteRule ... [P]") from mod_rewrite because its doesn't depend on a corresponding ProxyPass directive.

When used inside a section, the first argument is ommitted and the local directory is obtained from the .
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
(三).实际问题解决及说明:


   ProxyPass /mysys/
   ProxyPassReverse /mysys/



① 这里有两个mysys,我们分别叫做叫做path_wapm和path_iis

ProxyPass /path_wapm/
  
   path_wapm:这个是虚拟的目录名称,可以任意指定一个

②ProxyPassReverse /path_wapm/
  
   path_iis:这个必须通过81端口可以访问的


那么,访问服务器/path_wapm的时候,实际访问的将自动转换为了
的.

③path_wapm如果不加,就不知道访问哪一个虚拟目录的时候需要使用ASP,

path_iis不加,那么就是访问的效果了

简单来说:就是把IIS站点的一个目录,当作WAPM的一个虚拟目录来访问,
可以是IIS站点的一个子目录,也可以是根目录.
 

servername
ServerAlias *.main_web.com
DocumentRoot "D:/Tomcat 5.5/webapps/main_web"
DirectoryIndex index.jsp index.php index.htm index.html
#ProxyPass /images/ !
ProxyPass / ajp://127.0.0.1:8009/
ProxyPassReverse / ajp://127.0.0.1:8009/



ServerName
ServerAlias *.web1.com
DocumentRoot D:/wz/dy/web1
DirectoryIndex index.jsp index.php index.htm index.html
ErrorLog logs/web1/error.log
CustomLog logs/web1/access.log combined
ProxyPass / http://:8080/
ProxyPassReverse / http://:8080/
 
 
 
 
阅读(1442) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~