如何为子域设置虚拟主机?

时间:2016-01-12 15:34:04

标签: php apache virtualhost

我有一个子域名。我想使用xampp(apache)在本地设置虚拟主机。

例如,我想使用test.mywebsite.com 我想通过打开这个子域来运行本地文件。

我已经尝试过几乎所有文章/帮助材料在线设置虚拟主机的子域名但是徒劳无功。

我试过以下但没有任何作用:

的httpd-vhosts.conf:

<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/project"
ServerName mywebsite.com
ServerAlias test.mywebsite.com

托管文件:

127.0.0.1 mywebsite.com
127.0.0.1 test.mywebsite.com

我会感激任何建议/帮助。 感谢

1 个答案:

答案 0 :(得分:0)

修改C:\xampp\apache\conf\extra\httpd-vhosts.conf并添加以下行。确保将dir替换为原始文档根目录。

<VirtualHost *:80>
    ServerName  test.mywebsite.com
    DocumentRoot "C:\xampp\htdocs\dir"
    <Directory "C:\xampp\htdocs\dir">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

重新启动apache,然后编辑C:\Windows\System32\Drivers\etc\hosts并在底部添加以下行。

127.0.0.1 test.mywebsite.com