好的,所以这里的问题是网络。我能够重现这个问题。首先,请禁用 Vagrant 中的端口转发。只是评论config.vm.network "forwarded_port", guest: 80, host: 8070
并做一个vagrant reload
.要使其正常工作,您需要检查主机的 IP 地址,然后转到 Vagrant 文件并编辑config.vm.network "private_network", ip: "X.X.X.X"
这样这里的ip地址实际上和你的主机在同一个网络上。我所做的只是将最后一个八位字节增加 1。我的本地 IP 地址是 192.168.23.45,因此我将 192.168.23.46 分配给 Vagrant 来宾。
一旦完成此操作,也许您只需使用即可省去所有麻烦thisshell 脚本为您自己创建虚拟主机。我已将输出粘贴在下面,您可以查看我已使用 mysite1 和 mysite2 名称设置了两个虚拟主机。
然后只需将主机文件条目放在您的主机上,如下所示:
192.168.23.46 mysite1
192.168.23.46 mysite2
并使用访问该网站http://mysite1 and http://mysite2。您可能想要更改脚本放置在相应文档根目录下的index.php的内容,以便您可以确保请求由正确的虚拟主机处理,因为该脚本只处理apache的默认index.php将在您的两个文档根目录下找到。
另一种选择是让 Vagrant box 在公共网络上可用,然后
使用公共 IP 访问它,为此,您必须启用config.vm.network "public_network"
在 Vagrant 文件中,创建虚拟主机的其余过程是相同的(使用此脚本)。
[root@localhost vagrant]# bash test.sh
Enter the server name your want (without www) : mysite1
Enter a CNAME (e.g. :www or dev for dev.website.com) : mysite1
Enter the path of directory you wanna use (e.g. : /var/www/, dont forget the /): /var/www/mysite1/
Enter the user you wanna use (e.g. : apache) : apache
Enter the listened IP for the server (e.g. : *): *
Web directory created with success !
/etc/httpd/conf.d/mysite1.conf
Virtual host created !
Would you like me to create ssl virtual host [y/n]?
n
Testing configuration
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK
Would you like me to restart the server [y/n]?
y
Redirecting to /bin/systemctl restart httpd.service
======================================
All works done! You should be able to see your website at http://mysite1
Share the love! <3
======================================
Wanna contribute to improve this script? Found a bug? https://gist.github.com/mattmezza/2e326ba2f1352a4b42b8
[root@localhost vagrant]# bash test.sh
Enter the server name your want (without www) : mysite2
Enter a CNAME (e.g. :www or dev for dev.website.com) : mysite2
Enter the path of directory you wanna use (e.g. : /var/www/, dont forget the /): /var/www/mysite2/
Enter the user you wanna use (e.g. : apache) : apache
Enter the listened IP for the server (e.g. : *): *
Web directory created with success !
/etc/httpd/conf.d/mysite2.conf
Virtual host created !
Would you like me to create ssl virtual host [y/n]?
n
Testing configuration
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK
Would you like me to restart the server [y/n]?
y
Redirecting to /bin/systemctl restart httpd.service
======================================
All works done! You should be able to see your website at http://mysite2
Share the love! <3
======================================
Wanna contribute to improve this script? Found a bug? https://gist.github.com/mattmezza/2e326ba2f1352a4b42b8
如果您需要更多说明,请告诉我。