<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[个人原创]Apache多虚拟机配置下如何通过直接输入IP后确定指向哪个域名的方法，以及实践中发现apache加上虚拟主机后，用ip访问并不是指向刚安好Apache时的默认Web目录的解决办法。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Thu, 15 Sep 2011 02:15:21 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	通过测试和在PHP高级群里询问得知默认指向了我的一个虚拟机的网站，但是我们往往配置是这样的：<br/><textarea name="code" class="html" rows="15" cols="100">
NameVirtualHost *:80
Include conf/vhost/*.conf
</textarea><br/>这个*.conf不知Apache去指向哪个虚拟主机了，于是，就在上面加了一个，成这样了：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;VirtualHost *:80&gt;
ServerName phpdoc.webdev.com
DocumentRoot /usr/local/apache2/htdocs
DirectoryIndex index.php index.html web_adc.html
&lt;ifmodule mod_expires.c&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExpiresActive On
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExpiresDefault&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;access plus 1 days&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExpiresByType image/gif&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;access plus 1 days&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExpiresByType image/jpeg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;access plus 1 days&quot;
&lt;/ifmodule&gt;
&lt;/VirtualHost&gt;
NameVirtualHost *:80
</textarea><br/><br/><br/>经测试，直接输入IP访问时就是指向了/usr/local/apache2/htdocs 目录了，呵呵。<br/>PHP高级群里有兄弟问：<br/><textarea name="code" class="html" rows="15" cols="100">
NameVirtualHost *:80
</textarea><br/>要放在所有的VirtualHost前面吧？<br/>答：<br/>放后面也没关系。<br/>一样的，我试了。<br/><br/>---------------------再次实践总结----------------------------<br/>再次配置时，发现用apache的虚拟主机挂了好几个域名。&nbsp;&nbsp;然后几天遇到的问题是如果直接用ip访问，或者用了一个未配置的域名的访问,那么刷出来的页面竟然不是apache的欢迎页，而是虚拟主机配置中的第一个域名。<br/>原因分析并实践Ok如下：<br/>&nbsp;&nbsp; apache网站解释为当一个请求到达的时候，服务器会首先检查它是否使用了一个能和<br/>NameVirtualHost相匹配的IP地址。如果能够匹配， 它就会查找每个与这个IP地址相对应的<br/>配置段， 并尝试找出一个ServerName或ServerAlias配置项与请求的主机名相同的。如果<br/>找到了，它就会使用这个服务器的配置。 否则，将使用符合这个IP地址的第一个列出的虚拟主机。<br/>其实这个时候，比如用ip直接访问，IE浏览器会提示他已经超出访问范围了。。<br/>解决这个的问题的方案是添加下面的配置到虚拟机主机配置文件中（也就是如果有虚拟机后Apache不会去默认的那个DocumentRoot &quot;d:/wamp/www/&quot; 里，如果用IP访问Apache而是会去找第一个虚拟机的DocumentRoot ），要想在配置虚拟域名后还能指向当前的默认的那个DocumentRoot ，则在虚拟机配置的第一个加上一个指向默认的那个DocumentRoot目录的虚拟机配置即可）。<br/>如下配置：&nbsp;&nbsp;&nbsp;&nbsp;<br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;DocumentRoot &quot;d:/wamp/www/&quot;
&nbsp;&nbsp;&lt;Directory &quot;d:/wamp/www/&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order Allow,Deny
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Allow from all
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;......
&nbsp;&nbsp;&lt;/Directory&gt;
&nbsp;&nbsp;...上面的配置因为加了虚拟机配置后默认用IP访问的指向地址已经失效进而出现默认用IP访问时指向第一个虚拟机，为此，为了保证它是指向我们想要的默认目录则在下面虚拟机的配置前再加一个虚拟机即可...
&nbsp;&nbsp;&lt;VirtualHost *:80&gt;
&nbsp;&nbsp;ServerAdmin webmaster@jackxiang.com
&nbsp;&nbsp;DocumentRoot &quot;d:/wamp/www/&quot;
&nbsp;&nbsp;ServerName jackxiang.com
&nbsp;&nbsp;ErrorLog &quot;logs/jackxiang-error.log&quot;
&nbsp;&nbsp;CustomLog &quot;logs/jackxiang-access.log&quot; common
&nbsp;&nbsp;&lt;Directory &quot;d:/wamp/www/&quot;&gt;
&nbsp;&nbsp;Options Indexes FollowSymLinks MultiViews
&nbsp;&nbsp;AllowOverride all
&nbsp;&nbsp;Order Deny,Allow
&nbsp;&nbsp;Deny from all
&nbsp;&nbsp;Allow from all
&nbsp;&nbsp;&lt;/Directory&gt;
&nbsp;&nbsp;&lt;/VirtualHost&gt;

&nbsp;&nbsp;# Virtual hosts
&nbsp;&nbsp;Include conf/extra/httpd-vhosts.conf
</textarea><br/><br/>===========================================================================<br/>apache 设置禁止IP直接访问：<br/>刚好相反的对防止用IP访问到网站的方法，附录：<br/>1.建一个虚拟机提示错误<br/>apache虚拟主机默认情况下ip地址方式访问对应第一个虚拟主机，所以我们可以先建一个指向错误页面的虚拟主机，达到禁止用ip访问网页的目的。<br/>&lt;VirtualHost *:80&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ServerAdmin ngnix@qq.com<br/>&nbsp;&nbsp;&nbsp;&nbsp;DocumentRoot &quot;/usr/local/apache2.2.22/htdocs&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ServerName 192.168.3.140<br/>&lt;/VirtualHost&gt;<br/>echo &quot;请不要用IP访问&quot; &gt;/usr/local/apache2.2.22/htdocs/index.html<br/>2.直接限制访问<br/>&lt;VirtualHost *:80&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ServerAdmin ngnix@qq.com<br/>&nbsp;&nbsp;&nbsp;&nbsp;DocumentRoot &quot;/usr/local/apache2.2.22/htdocs&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ServerName 192.168.3.140<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Directory /&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Order deny,allow<br/>&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Directory&gt;<br/>&lt;/VirtualHost&gt;<br/>注意：在配置虚拟主机的时候，因为http.conf默认配置了默认主机，所以可以将http.conf里面配置主机的部分全部注释掉，所有主机都在http_vhost.conf里面配置。
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [个人原创]Apache多虚拟机配置下如何通过直接输入IP后确定指向哪个域名的方法，以及实践中发现apache加上虚拟主机后，用ip访问并不是指向刚安好Apache时的默认Web目录的解决办法。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>