设置 apache 虚拟主机(Windows)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2658173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:16:15  来源:igfitidea点击:

setup apache virtualhost (windows)

windowsapachewebservervirtualhost

提问by nightingale2k1

How to setup virtualhost for multiple domain name on windows ? I will use it for my own test projects. I have 3 projects that I need to setup and at the moment I'm using xampplite for the portable apache.

如何在 Windows 上为多个域名设置虚拟主机?我会将它用于我自己的测试项目。我有 3 个项目需要设置,目前我正在将 xampplite 用于便携式 apache。

  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\
  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\

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

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

how to write the vhost configuration for that ?

如何为此编写 vhost 配置?

回答by MicE

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

您需要执行几个步骤才能完成这项工作。


1.) Update the hostsfile.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.


1.) 更新hosts文件。在 Windows XP 上,您可以在c:\WINDOWS\system32\drivers\etc\. 您应该已经看到下面的第一行,它负责您提到的其他项目。- 添加额外的,以向路由回您自己的机器的上述虚拟主机发出任何请求。

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


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


2.) 更新 Apache 配置中的 vhosts 文件。在您的 XAMPP 文件夹下,添加以下内容apache\conf\extra\httpd-vhosts.conf并根据需要更改端口(即,如果您使用 8080 而不是端口 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>


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


3.) 进行快速配置检查。打开{XAMPP-folder}\apache\conf\httpd.conf您的文件并确保以下部分没有被前面的#字符注释掉:

Include conf/extra/httpd-vhosts.conf


4.) Restart XAMPP.


4.) 重新启动 XAMPP。

... 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/.

...你现在应该已经设置好了。如果您只是将它放在C:/xampplite/htdocs/my-project/.

回答by JeroenVdb

To get C:/xampp/htdocs/my-project/working I had to add the following (default?) VirtualHost to apache\conf\extra\httpd-vhosts.conf(in step 2 of MicE tutorial).

为了开始C:/xampp/htdocs/my-project/工作,我必须将以下(默认?)VirtualHost 添加到apache\conf\extra\httpd-vhosts.conf(在 MicE 教程的第 2 步中)。

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

回答by Anand computer gyaan

127.0.0.5  abcd.com

<  VirtualHost 127.0.0.5 >

    ServerName abcd.com

    DocumentRoot "C:\xampp\htdocs\laravel\public" 

    <Directory "C:\xampp\htdocs\laravel\public">

        DirectoryIndex index.php

        AllowOverride All

        Order allow, deny

        Allow from all

    </Directory>

< / VirtualHost >