好的,我有两个 Linux 机器在代理服务器后面运行。两个盒子都设置为通过连接到端口 801 来绕过过滤。
框 A - Fedora Core 12/PHP 5.3.1
框 B - RHEL 6/PHP 5.3.3
在 Box A 上,我可以使用 file_get_contents() 连接到外部站点。
<?php
$opts = array(
'http' => array(
'proxy' => 'tcp://10.136.132.1:801',
'request_fulluri' => true
)
);
$cxContext = stream_context_set_default($opts);
echo file_get_contents("http://www.google.com");
这会导致显示 Google 的主页。
在 Box B 上,我运行相同的代码,但出现此错误:
Warning: file_get_contents(http://www.google.com): failed to open stream: Permission denied
两个盒子都在同一个网络上,在同一个代理服务器后面。 Apache 或 PHP 中是否缺少允许 file_get_contents 在 Box B 上工作的设置?
最佳答案
听起来您启用了 SELinux,默认情况下它会阻止 Apache 的任何传出连接。尝试以 root 身份在你的 shell 中运行它:
setsebool -P httpd_can_network_connect on
可以在此处找到有关 SELinux bool 值的更多信息: http://wiki.centos.org/TipsAndTricks/SelinuxBooleans
关于php - RHEL 6 上 PHP file_get_contents() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10398339/