今天突然想到以前的一个问题。那也是我面试的时候别人问我的
多个域名指定到同一个IP下,比如http://www.aaa.com/ http://www.bbb.com/ 两个站点,文件分别放在/usr/hosts/aaa /usr/hosts/bbb 下面。问了两个同事,最后发现原来自己很搞笑。
本地电脑上有很多个网站,一般我都通过建立虚拟域名来访问的。本地是WINDOWS操作系统
apache\conf\extra\httpd-vhosts.cond 文件里加上一段代码
<VirtualHost *:80> //我用的是80端口,如果是8080或者别的就替换上去
DocumentRoot E:/xampp/htdocs/server //文件放置的路径
ServerName dev.server //域名
</VirtualHost>
C:\WINDOWS\system32\drivers\etc\hosts 文件里加上
127.0.0.1 dev.server
保存重新启动APACHE
访问dev.rdserver就出来E:/xampp/htdocs/server 下面的文件
现在是不同的域名,同样的设置法
<VirtualHost *:80>
ServerAdmin admin@vigoicu.com
DocumentRoot "/usr/hosts/aaa" //文件路径
DirectoryIndex index.shtml index.html index.htm index.php login.php
AddType text ml .shtml
Addtype text ml .jsp
AddOutputFilter INCLUDES .shtml
ServerName www.aaa.com //域名
ErrorLog logs/ip.log
Customlog logs/ip.log common
AccessFileName dir.htaccess
DirectoryIndex index.shtml index.html page_1.shtml index.php index.html
ErrorDocument 404 /error/HTTP_NOT_FOUND.html
<Directory "/usr/local/apache docs/web/loader2009">
options -indexes
options Followsymlinks MultiViews IncludesNoExec
options +Includes
AddOutputFilter Includes html
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
记得要把NameVirtualHost *:80前面的# 去掉。不然APACHE不知道你设置的端口是多少
最后非常感谢我的两位同事帮忙。