设置apache虚拟主机(windows)

问题描述 投票:44回答:3

如何在Windows上为多个域名设置虚拟主机?我将它用于我自己的测试项目。我有3个项目需要设置,目前我正在使用xampplite进行可移植的apache。

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

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

如何编写vhost配置?

windows apache webserver virtualhost
3个回答
106
投票

您需要执行几个步骤才能使其工作。

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.)在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.)进行快速配置检查。打开{XAMPP-folder}\apache\conf\httpd.conf你的文件,并确保以前的#字符没有注释掉以下部分:

Include conf/extra/httpd-vhosts.conf

4.)重新启动XAMPP。

......现在你应该全部安装好了。如果您只是将它放在C:/xampplite/htdocs/my-project/下,那么您的其他项目应该可以通过您提到的URI访问。


6
投票

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

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

0
投票
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 > 
© www.soinside.com 2019 - 2024. All rights reserved.