﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-allen-文章分类-WEB MVC</title><link>http://www.blogjava.net/zhouzhou163/category/3641.html</link><description>专注于java ee技术,包括struts,jsf,webwork,spring,hibernate,ibatis</description><language>zh-cn</language><lastBuildDate>Sat, 24 Dec 2011 15:03:04 GMT</lastBuildDate><pubDate>Sat, 24 Dec 2011 15:03:04 GMT</pubDate><ttl>60</ttl><item><title>一个简单的php，算术运算验证码</title><link>http://www.blogjava.net/zhouzhou163/articles/366121.html</link><dc:creator>robbin163</dc:creator><author>robbin163</author><pubDate>Mon, 12 Dec 2011 02:17:00 GMT</pubDate><guid>http://www.blogjava.net/zhouzhou163/articles/366121.html</guid><wfw:comment>http://www.blogjava.net/zhouzhou163/comments/366121.html</wfw:comment><comments>http://www.blogjava.net/zhouzhou163/articles/366121.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhouzhou163/comments/commentRss/366121.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhouzhou163/services/trackbacks/366121.html</trackback:ping><description><![CDATA[因为防止恶意评论，所以要求加个验证码，要求简单，一般的２０以内的加法即可，根据其它网上的验证码，修改了下：<br /><div><div>&lt;?php&nbsp;</div><div>//session_start();</div><div>//生成验证码图片&nbsp;</div><div>Header("Content-type: image/PNG");&nbsp;</div><div>srand((double)microtime()*1000000);//播下一个生成随机数字的种子，以方便下面随机数生成的使用</div><div>//session_start();//将随机数存入session中</div><div>$_SESSION['authnum']="";</div><div>$im = imagecreate(70,20) or die("Cant's initialize new GD image stream!"); //制定图片背景大小</div><div>$black = ImageColorAllocate($im, 0,0,0); //设定三种颜色</div><div>$white = ImageColorAllocate($im, 255,255,255);&nbsp;</div><div>$gray = ImageColorAllocate($im, 200,200,200);</div><div></div><div>imagefill($im,0,0,$gray); //采用区域填充法，设定（0,0）</div><div></div><div>//生成数字和字母混合的验证码方法</div><div>//$ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";</div><div>$ychar="0,1,2,3,4,5,6,7,8,9";</div><div>$list=explode(",",$ychar);</div><div>$answer='';</div><div>$authnum=0;</div><div>for($i=0;$i&lt;2;$i++){</div><div>$randnum=rand(0,10);</div><div>$authnum=$authnum+intval($randnum);</div><div>error_log("auth:$authnum :dddd:$randnum",0);</div><div>$answer=$answer.intval($randnum)."+";</div><div>}</div><div>$answer=rtrim($answer,"+");</div><div>$answer=$answer.'=?';</div><div>//$authnum=''.$answer;</div><div>//while(($authnum=rand()%100000)&lt;10000); //生成随机的五们数</div><div>//将五位整数验证码绘入图片&nbsp;</div><div>//$_COOKIE['authnum']=$authnum;</div><div>//error_log("auth:$authnum",0);</div><div>setCookie("authnum",$authnum,null,'/');</div><div></div><div>//imagestring($im, 5, 10, 3, $authnum, $black);</div><div>imagestring($im, 5, 10, 3, $answer, $black);</div><div>// 用 col 颜色将字符串 s 画到 image 所代表的图像的 x，y 座标处（图像的左上角为 0, 0）。</div><div>//如果 font 是 1，2，3，4 或 5，则使用内置字体</div><div></div><div>/*</div><div>for($i=0;$i&lt;200;$i++) //加入干扰象素&nbsp;</div><div>{&nbsp;</div><div>$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));</div><div>imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);&nbsp;</div><div>}&nbsp;</div><div>&nbsp;</div><div>&nbsp;*/</div><div>ImagePNG($im);&nbsp;</div><div>ImageDestroy($im);<br /><br /></div></div><img src ="http://www.blogjava.net/zhouzhou163/aggbug/366121.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhouzhou163/" target="_blank">robbin163</a> 2011-12-12 10:17 <a href="http://www.blogjava.net/zhouzhou163/articles/366121.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache:在一个IP地址上运行多个基于域名的web站点  转载</title><link>http://www.blogjava.net/zhouzhou163/articles/336930.html</link><dc:creator>robbin163</dc:creator><author>robbin163</author><pubDate>Wed, 03 Nov 2010 06:57:00 GMT</pubDate><guid>http://www.blogjava.net/zhouzhou163/articles/336930.html</guid><description><![CDATA[<p><font  face="Tahoma, Arial" size="4"><span  style="font-size: 14px; line-height: 19px;">作者：linlonx@灵龙-技术 实验室 地址：http://www.linlonx.com/post/288/</span></font></p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;您的服务器有只一个IP地址，而在DNS中有很多域名(CNAMES)映射到这个机器。您而您想要在这个机器上运行<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a>和<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a>两个站点。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;注意<br />
&nbsp;&nbsp;在您的Apache服务器配置中创建一个虚拟主机并不会自动在您的DNS中对主机名做相应更新。您必须自己在DNS中添加域名来指向您的IP地址。否则别人是无法看到您的web站点的。您可以在您的hosts文件中添加这一条目来进行测试，但这种方法仅适用于那些有这些hosts文件的机器来使用。&nbsp;<a name="entrymore" style="text-decoration: none; color: #333333; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a></p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;# 确保Apache在监听80端口<br />
&nbsp;&nbsp;Listen 80</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# 为虚拟主机在所有IP地址上监听<br />
&nbsp;&nbsp;NameVirtualHost *:80</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost *:80&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example1<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a></p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# 你可以在这里添加其他指令</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost *:80&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a></p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# 你可以在这里添加其他指令</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;因为星号匹配所有IP地址，所以主服务器不接收任何请求。因为<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a>首先出现在配置文件中，所以它拥有最高优先级，可以认为是默认或主服务器。这意味着如果一个请求不能与某个ServerName指令相匹配，它将会由第一个&lt;VirtualHost&gt;段所伺服。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;注意<br />
&nbsp;&nbsp;如果您愿意，您可以用确定的IP地址来取代"*"。在这种情况下，VirtualHost的参数必须与NameVirtualHost的参数相符：</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;NameVirtualHost 172.20.30.40</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;# 其他 ...</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;然而，当您的IP地址无法确定的时候，使用"*"是很方便的，比如说，您的ISP给您配置的是动态IP地址，而您又使用了某种动态域名解析系统时。因为"*"匹配任何IP地址，所以在这种情况下，不论IP地址如何变化，您都不需要另外进行配置。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;上述配置就是您在绝大多数情况下使用基于域名的虚拟主机时将要用到的。事实上，仅在一种情况下这样的配置不会让您满意：您想为不同的IP地址或是端口提供不同的内容。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;在多于一个IP的情况下使用基于域名的虚拟主机。<br />
&nbsp;&nbsp;注意<br />
&nbsp;&nbsp;在这里讨论的任何技术都可以推广到使用任意数量的IP地址。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器有两个IP地址。一个(172.20.30.40)用于主服务器server.domain.com ，另外一个(172.20.30.50)用于构建两个或多个虚拟主机。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;Listen 80</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# "主"服务器运行于：172.20.30.40<br />
&nbsp;&nbsp;ServerName server.domain.com<br />
&nbsp;&nbsp;DocumentRoot /www/mainserver</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# 这是另外一个IP地址<br />
&nbsp;&nbsp;NameVirtualHost 172.20.30.50</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.50&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example1<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a></p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# 你可以在这里添加其他指令 ...</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.50&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a></p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# 你可以在这里添加其他指令 ...</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;任何不是针对172.20.30.50的请求都将由主服务器来伺服。而提交给172.20.30.50却没有主机名或没有"Host:"头的请求，都将由ww.example.com伺服。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;在不同的IP的地址(比如一个内部和一个外部地址)上提供相同的内容<br />
&nbsp;&nbsp;服务器有两个IP地址(192.168.1.1和172.20.30.40)。这个机器位于内部(局域网)网络和外部(广域网)之间。在外部，域名server.example.com指向外部地址(172.20.30.40)，而在内部则指向内部地址(192.168.1.1)。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器可以为来自内部和外部的请求提供同样的内容，您只需要一个&lt;VirtualHost&gt;配置段就可以了。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;NameVirtualHost 192.168.1.1<br />
&nbsp;&nbsp;NameVirtualHost 172.20.30.40</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 192.168.1.1 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/server1<br />
&nbsp;&nbsp;ServerName server.example.com<br />
&nbsp;&nbsp;ServerAlias server<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;现在，从不同的网络提交的请求都会由同一个&lt;VirtualHost&gt;段来伺服。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;注意<br />
&nbsp;&nbsp;在内网中，您可以使用server这个名字来代替server.example.com这个全名。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;跟上面一样，在上述的例子里，您可以用"*"来代替具体的IP地址，这样就可以对所有的地址都返回相同的内容了。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;在不同的端口上运行不同的站点<br />
&nbsp;&nbsp;如果您想让同一个IP的不同端口伺服多个域名。您可以借助在NameVirtualHost指令中定义端口的方法来达到这个目的。如果您想使用不带"name:port"的&lt;VirtualHost name:port&gt;或是直接用Listen指令，您的配置将无法生效。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;Listen 80<br />
&nbsp;&nbsp;Listen 8080</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;NameVirtualHost 172.20.30.40:80<br />
&nbsp;&nbsp;NameVirtualHost 172.20.30.40:8080</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40:80&gt;<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;DocumentRoot /www/domain-80<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40:8080&gt;<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;DocumentRoot /www/domain-8080<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40:80&gt;<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;DocumentRoot /www/otherdomain-80<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40:8080&gt;<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;DocumentRoot /www/otherdomain-8080<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;建立基于IP的虚拟主机<br />
&nbsp;&nbsp;一个有两个IP地址(172.20.30.40和172.20.30.50)分别对应域名<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a>和<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a>的配置如下：</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;Listen 80</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example1<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.50&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;如果存在主服务器，那么对没有出现在任一个&lt;VirtualHost&gt;段中的请求(比如，对localhost的请求)都会由主服务器来伺服。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;混用基于端口和基于IP的虚拟主机<br />
&nbsp;&nbsp;如果您的服务器有两个IP地址(172.20.30.40和172.20.30.50)分别对应域名<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a>和<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a>&nbsp;。对每个域名，您都希望在80端口和8080端口发布您的网站。您可以这样配置：</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;Listen 172.20.30.40:80<br />
&nbsp;&nbsp;Listen 172.20.30.40:8080<br />
&nbsp;&nbsp;Listen 172.20.30.50:80<br />
&nbsp;&nbsp;Listen 172.20.30.50:8080</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40:80&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example1-80<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40:8080&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example1-8080<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.50:80&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2-80<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.50:8080&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2-8080<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;混用基于域名和基于IP的虚拟主机<br />
&nbsp;&nbsp;您想在一些地址上配置基于域名的虚拟主机而在另外一些地址上配置基于IP的虚拟主机。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;Listen 80</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;NameVirtualHost 172.20.30.40</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example1<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example3<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example3.net/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example3.net/" target="_blank" style="text-decoration: none; color: #333333; ">www.example3.net</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;# IP-based<br />
&nbsp;&nbsp;&lt;VirtualHost 172.20.30.50&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example4<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example4.edu/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example4.edu/" target="_blank" style="text-decoration: none; color: #333333; ">www.example4.edu</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.60&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example5<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example5.gov/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example5.gov/" target="_blank" style="text-decoration: none; color: #333333; ">www.example5.gov</a><br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;将&lt;Virtual_host&gt;和mod_proxy模块一起使用<br />
&nbsp;&nbsp;下面的例子允许一个前端机器代理一个运行在其他机器上的虚拟主机。在如下示例中，在192.168.111.2机器上配置了一个同名的虚拟主机。这样，万一在同一台机器上代理了多个主机名，ProxyPreserveHostOn 指令能确保指定的主机名顺利通过代理。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost *:*&gt;<br />
&nbsp;&nbsp;ProxyPreserveHost On<br />
&nbsp;&nbsp;ProxyPass /&nbsp;<a href="http://192.168.111.2/" style="text-decoration: none; color: #333333; "></a><a href="http://192.168.111.2/" target="_blank" style="text-decoration: none; color: #333333; ">http://192.168.111.2</a><br />
&nbsp;&nbsp;ProxyPassReverse /&nbsp;<a href="http://192.168.111.2/" style="text-decoration: none; color: #333333; "></a><a href="http://192.168.111.2/" target="_blank" style="text-decoration: none; color: #333333; ">http://192.168.111.2/</a><br />
&nbsp;&nbsp;ServerName hostname.example.com<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;使用"_default_"虚拟主机<br />
&nbsp;&nbsp;为所有端口配置"_default_"虚拟主机<br />
&nbsp;&nbsp;这样配置可以捕获所有指向没指定的IP地址和端口的请求。比如：一个没被任何虚拟主机使用的地址/端口对。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;&lt;VirtualHost _default_:*&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/default<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;这样一个使用通配符端口的默认虚拟主机可以有效的防止请求被主服务器接收。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;如果一个地址/端口对已经被一个基于域名的虚拟主机使用，那么"_default_"虚拟主机决不会处理发向这个地址/端口对的请求。如果一个"Host:"请求头中包含未知信息，或者干脆就没有，那么它会被第一个基于域名的虚拟主机(也就是在配置文件中最先出现的使用了那个地址/端口对的虚拟主机)处理。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;您可以用AliasMatch或RewriteRule来重写任何请求，使它指向一个简单信息页面(或脚本)。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;为不同的端口配置"_default_"虚拟主机<br />
&nbsp;&nbsp;与第一种一样，但我们想让服务器侦听很多端口而第二个"_default_"虚拟主机单独侦听80端口。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;&lt;VirtualHost _default_:80&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/default80<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost _default_:*&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/default<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;侦听80端口的"_default_"虚拟主机(必须出现在所有使用通配符端口的虚拟主机之前)会捕获所有发向一个未指定的IP地址的请求。主服务器将不会用于伺服任何请求。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;为单独一个端口配置"_default_"虚拟主机<br />
&nbsp;&nbsp;如果我们只想在80端口上建立唯一的一个"_default_"虚拟主机，我们应该这样配置：</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;&lt;VirtualHost _default_:80&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/default<br />
&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;发向一个未指定地址的80端口的请求将会由这个虚拟主机伺服；而发向未设定地址的其他端口的请求则由主服务器伺服。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;将一个基于域名的虚拟主机移植为一个基于IP的虚拟主机<br />
&nbsp;&nbsp;如果一个具有ww.example.org域名的虚拟主机(就是基于域名配置示例中的第二个)得到了自己的IP地址。为了避免一些域名服务器或代理服务器在移植期间仍对这个域名做老的解析，我们可以采用一种过渡方法：同时提供新旧两个IP地址的解析。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;达到这个目的很简单。因为我们只要简单的把新地址(172.20.30.50)加入VirtualHost指令就行了。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;Listen 80<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.com/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.com/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.com</a><br />
&nbsp;&nbsp;DocumentRoot /www/example1</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;NameVirtualHost 172.20.30.40</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40 172.20.30.50&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example2<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.org/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.org/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.org</a><br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/example3<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.example.net/" style="text-decoration: none; color: #333333; "></a><a href="http://www.example.net/" target="_blank" style="text-decoration: none; color: #333333; ">www.example.net</a><br />
&nbsp;&nbsp;ServerAlias *.example.net<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;现在这个虚拟主机就可以用新地址(表现为一个基于IP的虚拟主机)和旧地址(表现为一个基于域名的虚拟主机)同时进行访问了。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;使用ServerPath指令<br />
&nbsp;&nbsp;如果我们在同一个服务器上运行了两个基于域名的虚拟主机。为了匹配正确的虚拟主机，客户端必须发送正确的"Host:" 头。而旧的使用HTTP/1.0的客户端无法发送这样的头，这样Apache就无法辨别客户端想要连接哪个虚拟主机(会用主虚拟主机来伺服这个请求)。为 了尽量提供向下兼容性，我们可以提供一个主虚拟主机来返回一个页面，在页面中加入指向基于域名的虚拟主机的URL前缀的链接。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;服务器配置<br />
&nbsp;&nbsp;NameVirtualHost 172.20.30.40</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;# 主虚拟主机<br />
&nbsp;&nbsp;DocumentRoot /www/subdomain<br />
&nbsp;&nbsp;RewriteEngine On<br />
&nbsp;&nbsp;RewriteRule ^/.* /www/subdomain/index.html<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/subdomain/sub1<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.sub1.domain.tld/" style="text-decoration: none; color: #333333; "></a><a href="http://www.sub1.domain.tld/" target="_blank" style="text-decoration: none; color: #333333; ">www.sub1.domain.tld</a><br />
&nbsp;&nbsp;ServerPath /sub1/<br />
&nbsp;&nbsp;RewriteEngine On<br />
&nbsp;&nbsp;RewriteRule ^(/sub1/.*) /www/subdomain$1<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;&lt;VirtualHost 172.20.30.40&gt;<br />
&nbsp;&nbsp;DocumentRoot /www/subdomain/sub2<br />
&nbsp;&nbsp;ServerName&nbsp;<a href="http://www.sub2.domain.tld/" style="text-decoration: none; color: #333333; "></a><a href="http://www.sub2.domain.tld/" target="_blank" style="text-decoration: none; color: #333333; ">www.sub2.domain.tld</a><br />
&nbsp;&nbsp;ServerPath /sub2/<br />
&nbsp;&nbsp;RewriteEngine On<br />
&nbsp;&nbsp;RewriteRule ^(/sub2/.*) /www/subdomain$1<br />
&nbsp;&nbsp;# ...<br />
&nbsp;&nbsp;&lt;/VirtualHost&gt;</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;由于ServerPath指令的作用，发送到htp://www.sub1.domain.tld/sub1/的请求总会被sub1-vhost所伺服。<br />
&nbsp;&nbsp;如果客户端发送了正确的"Host:"头，发送到htp://www.sub1.domain.tld、的请求只会被sub1-vhost所伺服。如果没有发送"Host:"头，客户端将会得到从主虚拟主机发送的信息页面。</p>
<p style="font-family: Tahoma, Arial; font-size: 14px; line-height: 19px; ">&nbsp;&nbsp;请注意，这里还有一点小问题：如果客户端没有发送"Host:"头，发送到<a href="http://www.sub2.domain.tld/sub1/" style="text-decoration: none; color: #333333; "></a><a href="http://www.sub2.domain.tld/sub1/" target="_blank" style="text-decoration: none; color: #333333; ">http://www.sub2.domain.tld/sub1/</a>的请求还是会被sub1-vhost所伺服。</p>
<img src ="http://www.blogjava.net/zhouzhou163/aggbug/336930.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhouzhou163/" target="_blank">robbin163</a> 2010-11-03 14:57 <a href="http://www.blogjava.net/zhouzhou163/articles/336930.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>