php - RHEL 6 上 PHP file_get_contents() 的问题

标签 php linux apache proxy file-get-contents

好的,我有两个 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/

相关文章:

javascript - 消息不显示

javascript - 通过从缩略图或下一个上一个按钮中选择来更改图像

linux - 在 Beaglebone black 上安装 Angstrom

linux - 生成网页的图像(例如 jpg)?

java - Apache 希罗 : Using isAuthenticated() || isRemembered() for an app without high security requirements

php - 使用 PHP5 配置 Apache2.2.15 时出错

php - 在动态导航 PHP 上突出显示当前页面

linux - 从 IP 地址和端口获取套接字 FD

Apache RewriteRule 不适用于单个输入

php - Apache/MySQL 问题