如何在Windows上为多个域名设置虚拟主机?我将它用于我自己的测试项目。我有3个项目需要设置,目前我正在使用xampplite进行可移植的apache。
我还需要访问另一个项目,但就像输入http://localhost/my-project/一样
如何编写vhost配置?
您需要执行几个步骤才能使其工作。
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访问。
为了让C:/xampp/htdocs/my-project/
工作,我必须将以下(默认?)VirtualHost添加到apache\conf\extra\httpd-vhosts.conf
(在MicE教程的第2步)。
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
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 >