在Windows上设置Apache virtualhost [英] Set up Apache virtualhost on Windows

查看:49
本文介绍了在Windows上设置Apache virtualhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Windows上为多个域名设置虚拟主机?

How can I set up virtualhost for multiple domain name on Windows?

我将其用于我自己的测试项目.我需要设置三个项目,目前我正在将xampplite用于可移植的Apache.

I will use it for my own test projects. I have three projects that I need to set up and at the moment I'm using xampplite for the portable Apache.

  1. www.foo-bar.com ->直接到c:\ xampplite \ htdocs \ foo-bar \
  2. www.abcdef.com ->定向到c:\ xampplite \ htdocs \ abcdef \
  3. www.qwerty.com ->直接到c:\ xampplite \ htdocs \ qwerty \ web \
  1. www.foo-bar.com --> direct to c:\xampplite\htdocs\foo-bar\
  2. www.abcdef.com --> directo to c:\xampplite\htdocs\abcdef\
  3. www.qwerty.com --> direct to c:\xampplite\htdocs\qwerty\web\

我还需要访问另一个项目,但这就像输入http://localhost/my-project/

I also need to access on another project, but it just like typing http://localhost/my-project/

如何为此编写虚拟主机配置?

How can I write the vhost configuration for that?

推荐答案

您需要执行几个步骤才能使此工作正常进行.

You need to do several steps in order to make this work.

  1. 更新主机文件.>在Windows XP上,您可以在 c:\ WINDOWS \ system32 \ drivers \ etc \ 下找到它.您应该已经从下面看到第一行.它会照顾您提到的其他项目.添加其他请求,以对路由回您自己的计算机的上述虚拟主机发出任何请求.

  1. Update the hosts file. On Windows XP, you can find it under c:\WINDOWS\system32\drivers\etc\. You should already see the first line from below. It takes care of your mentioned other project. Add the additional ones to make any requests to the mentioned virtual hosts routed back to your own machine.

 127.0.0.1       localhost
 127.0.0.1       foo-bar.com
 127.0.0.1       abcdef.com
 127.0.0.1       qwerty.com

  • 更新Apache配置中的vhosts文件.在XAMPP文件夹下,将以下内容添加到 apache \ conf \ extra \ httpd-vhosts.conf 中,如果需要更改端口(即,如果您使用8080而不是端口80).

  • Update the vhosts file in Apache configuration. Under your XAMPP folder, add the following to apache\conf\extra\httpd-vhosts.conf and if needed change the ports (i.e., if you use 8080 instead of port 80).

     <VirtualHost *:80>
         DocumentRoot C:/xampplite/htdocs/foo-bar/
         ServerName www.foo-bar.com
     </VirtualHost>
     <VirtualHost *:80>
         DocumentRoot C:/xampplite/htdocs/abcdef/
         ServerName www.abcdef.com
     </VirtualHost>
     <VirtualHost *:80>
         DocumentRoot C:/xampplite/htdocs/qwerty/web/
         ServerName www.qwerty.com
     </VirtualHost>
    

  • 进行快速配置检查.打开 {XAMPP-folder} \ apache \ conf \ httpd.conf ,并确保以下部分是前面的#字符未将其注释掉:

  • Do a quick configuration check. Open {XAMPP-folder}\apache\conf\httpd.conf your file and make sure that the following part is not commented out by a preceding # character:

     Include conf/extra/httpd-vhosts.conf
    

  • 重新启动XAMPP .

    ...,您现在应该已经完成​​所有设置.如果将其他项目放在 C:/xampplite/htdocs/my-project/下,则应该可以通过您提到的URI访问其他项目.

    ... and you should be all setup now. Your other project should be accessible at the URI you mentioned if you just put it under C:/xampplite/htdocs/my-project/.

    这篇关于在Windows上设置Apache virtualhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆