在 Xampp 服务器 windows 中创建子域

Creating subdomains in Xampp server windows

我正在尝试在我的本地主机上创建子域以供我的团队同时访问,但即使在浏览器中输入第二个域的 url 时,也只会加载第一个项目。

到目前为止,我已尝试更改 httpd-vhosts.conf 文件

    <VirtualHost *:80>
      ServerAdmin webmaster@smartsacco.localhost.com
      DocumentRoot "C:/xampp/htdocs/smartsacco/public"
      ServerName smartsacco.localhost.com
      ErrorLog "logs/smartsacco.localhost.com-error.log"
      CustomLog "logs/smartsacco.localhost.com-access.log" common
    </VirtualHost>
    <VirtualHost *:80>
      ServerAdmin webmaster@mfarmer.localhost.com
      DocumentRoot "C:/xampp/htdocs/Mfarmer/public"
      ServerName mfarmer.localhost.com
      ErrorLog "logs/mfarmer.localhost.com-error.log"
      CustomLog "logs/mfarmer.localhost.com-access.log" common
    </VirtualHost>

并且还修改了hosts文件

127.0.0.1       localhost
::1             localhost
127.0.0.1   smartsacco.localhost.com
127.0.0.1   mfarmer.localhost.com

遗憾的是,即使我键入 mfarmer.localhost.com,也只会加载 smartsacco.localhost.com 的内容。可能有什么问题,或者我该怎么做才能让它们都正常工作?

由于您的代码是正确的,我建议您重新启动 Apache 服务器,甚至可能是整个计算机