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构建的云服务器、香港云服务器、香港服务器、贵阳服务器、重庆服务器的租用和托管服务
如今我们网友可能较多的会选择云服务器、VPS主机,对于虚拟主机的话可能很多人不会选择。但是我们有些外贸业务用途的建站项目还是会有选择虚拟主机的。今天看到的Stablehost 商家虚拟主机在黑五期间也有四折优惠,对于这个服务商而言不是特别的喜欢,虽然他们商家和我们熟悉的老鹰主机商有些类似,且在后来老鹰主机改版和方案后,Stablehost 商家也会跟随改版,但是性价比认为不如老鹰主机。这次黑色星期...
NameSilo是通过之前的感恩节优惠活动中认识到这家注册商的,于是今天早上花了点时间专门了解了NameSilo优惠码和商家的详细信息。该商家只销售域名,他们家的域名销售价格还是中规中矩的,没有像godaddy域名标价和使用优惠之后的价格悬殊很大,而且其特色就是该域名平台提供免费的域名停放、免费隐私保护等功能。namesilo新注册域名价格列表,NameSilo官方网站:www.namesilo....
DiyVM是一家比较低调的国人主机商,成立于2009年,提供VPS主机和独立服务器租用等产品,其中VPS基于XEN(HVM)架构,数据中心包括香港沙田、美国洛杉矶和日本大阪等,CN2或者直连线路,支持异地备份与自定义镜像,可提供内网IP。本月商家最高提供5折优惠码,优惠后香港沙田CN2线路VPS最低2GB内存套餐每月仅50元起。香港(CN2)VPSCPU:2cores内存:2GB硬盘:50GB/R...