0

我有一个带有 apache 的 docker 容器,并使用虚拟主机配置了我的 .conf 文件,从客户端 test.dev 调用虚拟主机 docker 未映射。如果我调用 localhost 它可以正常工作。

谢谢!!

<VirtualHost *:80>
    Servername test.dev
    SetEnv APPLICATION_ENV "development"
    DocumentRoot "/var/www/html/test/public"
    <Directory "/var/www/html/test/public">
             DirectoryIndex index.php
             AllowOverride All
             Require all granted
    </Directory>
</VirtualHost>
4

1 回答 1

0

主机名不能“映射”到 docker 容器。如果您真的想使用主机名在本地访问它,您可能希望将 Host 标头注入每个请求或使用您的主机文件。

注入主机头

每当我想快速测试某些东西时,我通常会使用curl. 如果将容器绑定到主机上的 8080 端口:

curl -XGET -H "Host: test.dev" http://localhost:8080

配置主机文件

您必须添加127.0.0.1 test.dev到主机文件。该路径与您的操作系统相关:

  • 在 Windows 上:c:\windows\system32\drivers\etc\hosts
  • 在 Unix 上:/etc/hosts

完成后,您可以打开浏览器并前往http://test.dev:8080

于 2019-07-15T01:06:49.133 回答