问题描述
我在为我正在尝试开始的 yii2 高级应用程序项目设置虚拟主机名时遇到问题。
我为要服务的前端和后端设置了 httpd-vhosts.conf。该设置如下所示:
<VirtualHost *:8080>
ServerName testcodetube.test
DocumentRoot "C:\xampp\htdocs\TestCodeTube\frontend\web"
<Directory "C:\xampp\htdocs\TestCodeTube\frontend\web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists,use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.PHP
RewriteRule . index.PHP
# use index.PHP as index file
DirectoryIndex index.PHP
# ...other settings...
# Apache 2.4
Require all granted
## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerName studio.testcodetube.test
DocumentRoot "C:\xampp\htdocs\TestCodeTube\backend\web"
<Directory "C:\xampp\htdocs\TestCodeTube\backend\web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists,deny
# Allow from all
</Directory>
</VirtualHost>
我还编辑了目前看起来像这样的主机文件:
# Added by Docker Desktop
192.168.130.59 host.docker.internal
192.168.130.59 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
127.0.0.2 testcodetube.test
127.0.0.2 studio.testcodetube.test
所以现在奇怪的是,当我在搜索栏中输入 testcodetube.test 或 studio.testcodetube.test 时,它会将我重定向到默认的 Windows localhost 页面(包含多种语言的所有问候语),而不是我指定的目录。
如果我输入 localhost:8080 或 127.0.0.2:8080 它会提供正确的目录。另外,如果我 ping testcodetube.test 或 studio.testcodetube.test 我会得到一个成功的响应:
C:\xampp\htdocs>ping testcodetube.test
Pinging testcodetube.test [127.0.0.2] with 32 bytes of data:
Reply from 127.0.0.2: bytes=32 time<1ms TTL=128
Reply from 127.0.0.2: bytes=32 time<1ms TTL=128
Reply from 127.0.0.2: bytes=32 time<1ms TTL=128
Reply from 127.0.0.2: bytes=32 time<1ms TTL=128
我对此很陌生,所以我可能完全错了,但我很困惑如何知道与基于主机文件的正确端口进行通信,因为键入虚拟主机名似乎返回由 127.0.0.2(默认)而不是 127.0.0.2:80 提供的页面。所以对我来说,问题似乎是它没有与正确的端口通信,但我不知道如何修复它。
任何建议将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)