我已经按照documentation的状态设置了宅基地,并对Homestead.yaml
进行了以下更改以处理我的项目:
ip: 192.168.10.10
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
-
map: /home/pcmagas/Kwdikas/php/apps/ellakcy_member_app/
to: /home/vagrant/code
sites:
-
map: homestead.test
to: /home/vagrant/code/web
type: symfony
databases:
- homestead
name: ellakcy-member-app
hostname: ellakcy-member-app
但是当我通过浏览器http://192.168.10.10/
访问时,出现以下错误:
不允许您访问此文件。检查app_dev.php以获取更多信息。
答案 0 :(得分:0)
当您查看app_dev.php时,有以下代码片段:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
这意味着app_dev.php
脚本无法识别正在访问的ip,因此,为了防止在开发过程中进行任何未经授权的访问,它会阻止加载symfony。
为了绕过此保护措施,您应该弄清哪个客户的IP在无所事事的虚拟网络上,快速而肮脏的方法是用以下代码片段替换上面的代码片段:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true) || PHP_SAPI === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
echo 'REMOTE_ADDR: '.$_SERVER['REMOTE_ADDR']."<br>";
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
如您所见,它会打印出玩具应放置在数组中的正确值:
!(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'/*, Found Ip goes there*/], true)
就我而言,它是192.168.10.1
,我想也应该是您的情况。