Windows 下 Apache Virtualhost 设置

Apache with virtual host on Windows
一个很平常的问题,windows下怎么在apache上设置 virtualhost (虚拟主机),其实很简单。

这儿以xampp 为例。
第一,设置域名解析。
我们需要打开 host 这样一个文件,不同单位 windows 版本,其位置也不近相同,
Windows 3.1/95/98/ME:
c:\windows\hosts

Windows NT/2000/XP Pro:
c:\winnt\system32\drivers\etc\hosts or c:\windows\system32\drivers\etc\hosts

Windows XP Home:
c:\windows\system32\drivers\etc\hosts

Windows Vista:
C:\Windows\System32\Drivers\etc\hosts

用记事本打开 host 文件,如果你是vista,需要以administrator 运行记事本,在最下面添加:

127.0.0.1 wordpress.do
127.0.0.1 websitebaker.do

左边的ip 是这台电脑的IP地址,右边的是虚拟主机名(设置成功后就可以以这个虚拟主机名访问目录)。

第二,编辑httpd-vhosts.conf

用记事本打开httpd-vhosts.conf,该文件在xampp\apache\conf\extra,把下面的代码复制进去。

<VirtualHost *:80>
DocumentRoot /xampplite/htdocs
ServerName localhost
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName websitebaker.do #虚拟主机(virtualhost)
DocumentRoot D:/xampp/htdocs/websitebaker #网站物理地址
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory D:/xampp/htdocs/websitebaker>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName wordpress.do
DocumentRoot D:/xampp/htdocs/wordpress
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory D:/xampp/htdocs/wordpress>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

然后把 #NameVirtualHost *:80 前面的“#”去掉。保存文件退出。

第三,重新启动 apache service。

第四,OK,现在你可以用 http://wordpress.do 代替原来的http://localhost/wordpress 访问网站了.

转载于:https://my.oschina.net/zbrxtpgyaps/blog/23859

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值