在 Windows 上设置 Apache 虚拟主机 [英] Set up Apache virtualhost on Windows

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

问题描述

如何在 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/

我该如何为此编写 vhost 配置?

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 虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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