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构建的云服务器、香港云服务器、香港服务器、贵阳服务器、重庆服务器的租用和托管服务
wordpress外贸集团企业主题,wordpress通用跨屏外贸企业响应式布局设计,内置更完善的外贸企业网站优化推广功能,完善的企业产品营销展示 + 高效后台自定义设置。wordpress高级推广外贸主题,采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器,根据用户行为以及设备环境(系统平台、屏幕尺寸、屏幕定向等)进行自适应显示; 完美实现一套主题程序支持全部终端设备,保证网站在各...
百纵科技怎么样?百纵科技国人商家,ISP ICP 电信增值许可证的正规公司,近期上线美国C3机房洛杉矶独立服务器,大带宽/高配置多ip站群服务器。百纵科技拥有专业技术售后团队,机器支持自动化,自助安装系统 重启,开机交付时间 30分钟内交付!美国洛杉矶高防服务器配置特点: 硬件配置高 线路稳定 洛杉矶C3机房等级T4 平价销售,支持免费测试,美国独服适合做站,满意付款。点击进入:百纵科技官方网站地...
a400互联是一家成立于2020年商家,主营美国机房的产品,包括BGP线路、CN2 GIA线路的云服务器、独立服务器、高防服务器,接入线路优质,延迟低,稳定性高,额外也还有香港云服务器业务。当前,全场服务器5折,香港VPS7折,洛杉矶VPS5折,限时促销!A400互联官网:https://a400.net/优惠活动全场独服永久5折优惠(续费同价):0722香港VPS七折优惠:0711洛杉矶VPS五...