1.找到Apache的conf目录下的httpd.conf文件打开它找到下面这两行# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
把它改成下面这样
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
意思是启用虚拟主机的设置文件httpd-vhosts.conf虚拟主机的设置都在这个文件下设置不用去改httpd.conf,这样比较清晰。
2.找到Apache的confextra目录下的httpd-vhost.conf这个文件。
打开它的时候里面已经含有像下面这样的内容
–虚拟主机配置开始
ServerAdmin webmaster@dummy-host. localhost
DocumentRoot “C:/Program Files/Apache Software
Foundation/Apache2.2/docs/dummy-host. localhost”
ServerName dummy-host. localhost
ServerAlias www.dummy-host. localhost
ErrorLog “logs/dummy-host. localhost-error. log”
CustomLog “logs/dummy-host. localhost-access. log” common
COPY上面这几行关键是把
DocumentRoot “” –虚拟主机的目录 即域名对应的根目录
ServerName dummy-host. localhost –你想要的域名。
还要在每个虚拟主机配置开始前加入以下内容
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
其中
–这是你的虚拟主机的被授权的目录
一般与
DocumentRoot “” –虚拟主机的目录 即域名对应的根目录
相同。
Allow from all –这句是重点只要allow别人才行访问上面定义的目录否则在IE或firefox访问时会显示503错误 即禁止访问。
如果你不想在httpd-vhost. conf里加入
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
那么你也可以这样做
在httpd.conf里找到以下内容
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
这是Apache默认的设置最后一行是这样的
Deny from all
意思是拒绝所有访问对根目录的访问别人是访问不了你的网站的所以要改成
Allow from all
不过还是建议用第一种方法 即修改httpd-vhost.conf的内容这样比较清楚也比较安全。这样apache的设置就完成了不过还要做下面这一步。
3.还有关键的一步
这一步不做一定不行因为你本地的机器没有DNS解析。
找到C:WINDOWSsystem32driversetc目录下的hosts文件
加上这样的记录
127.0.0. 1 demoa–这个是你的域名你要设置多少个虚拟主机就要加多少行这样的记录。OK现在你可以设置N+1个域名了。
也可以参考一下这个地址 http://httpd.apache.org/docs/2.0/vhosts/examples.html 样例
--------------------------------------------------------------------------
ServerAdmin webmaster@dummy-host. localhost
DocumentRoot /www/docs/dummy-host. localhost
ServerName dummy-host. localhost
ServerAlias www.dummy-host. localhost
ErrorLog logs/dummy-host. localhost-error_log
CustomLog logs/dummy-host. localhost-access_log common
ServerAdmin webmaster@dummy-host2. localhost
DocumentRoot /www/docs/dummy-host2. localhost
ServerName dummy-host2. localhost
ErrorLog logs/dummy-host2. localhost-error_log
CustomLog logs/dummy-host2. localhost-access_log common
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
ServerAdmin webmaster@dummy-host2. localhost
DocumentRoot D:phpwork
ServerName localhost
ErrorLog logs/dummy-host2. localhost-error_log
CustomLog logs/dummy-host2. localhost-access_log common Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All
Order allow,deny
Allow from all
ServerAdmin webmaster@dummy-host2. localhost
DocumentRoot D:phpworkphpMyAdmin
ServerName phpMyAdmin. local
ErrorLog logs/dummy-host2. localhost-error_log
CustomLog logs/dummy-host2. localhost-access_log common Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All
Order allow,deny
Allow from all
ServerAdmin webmaster@dummy-host2. localhost
DocumentRoot D:phpwork est
ServerName test. local
ErrorLog logs/dummy-host2. localhost-error_log
CustomLog logs/dummy-host2. localhost-access_log common
知了云(https://www. zllyun.com) 行业领先的企业级云计算服务平台提供基于OpenStack构建的云服务器、香港云服务器、香港服务器、贵阳服务器、重庆服务器的租用和托管服务
Bluehost怎么样,Bluehost好不好,Bluehost成立十八周年全场虚拟主机优惠促销活动开始,购买12个月赠送主流域名和SSL证书,Bluehost是老牌虚拟主机商家了,有需要虚拟主机的朋友赶紧入手吧,活动时间:美国MST时间7月6日中午12:00到8月13日晚上11:59。Bluehost成立于2003年,主营WordPress托管、虚拟主机、VPS主机、专用服务器业务。Blueho...
bgp.to在对日本东京的独立服务器进行6.5折终身优惠促销,低至$120/月;对新加坡独立服务器进行7.5折终身优惠促销,低至$93/月。所有服务器都是直连国内,速度上面相比欧洲、美国有明显的优势,特别适合建站、远程办公等多种用途。官方网站:https://www.bgp.to/dedicated.html主打日本(东京、大阪)、新加坡、香港(CN)、洛杉矶(US)的服务器业务!日本服务器CPU...
易速互联怎么样?易速互联是国人老牌主机商家,至今已经成立9年,商家销售虚拟主机、VPS及独立服务器,目前商家针对美国加州萨克拉门托RH数据中心进行促销,线路采用BGP直连线路,自带10G防御,美国加州地区,100M带宽不限流量,月付299元起,有需要美国不限流量独立服务器的朋友可以看看。点击进入:易速互联官方网站美国独立服务器优惠套餐:RH数据中心位于美国加州、配置丰富性价比高、10G DDOS免...