通过 HTTP 代理的 Apachecurl

发布于 2024-10-04 14:37:00 字数 219 浏览 10 评论 0原文

我正在尝试让 PHP 执行与另一台服务器的curl 连接。要连接到服务器,我们需要通过代理。 在 bash 中,我们设置了环境变量 http_proxy,并且在从命令行使用 php 脚本时可以正常工作。但是,当尝试从 apache 执行 curl 或 wget 时,它会失败且没有错误。 服务器基于 Centos 默认配置了 SELinux。这一点没有改变,因为我不确定 SELinux 配置。 还有其他人有类似的问题吗?

I am trying to get PHP to execute a curl connection to another server. To connect to the server, we need to go via a proxy.
Within bash, we have set the env-variable http_proxy and this works correctly while using the php script from the command-line. However, when attempting to execute curl, or wget from apache, it fails with no errors.
The server is configured with SELinux based on Centos defaults. This has been unchanged as I am unsure about SELinux configuration.
Has anyone else had a similar issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稍尽春風 2024-10-11 14:37:00

抱歉回复晚了。
这是因为 SELinux 阻止 apache 执行对网络的调用。为了允许 apache 执行此操作,您需要运行:

setsebool -P httpd_can_network_connect 1

然后我遇到了另一个相关问题,我需要从命令行执行脚本,但找不到合适的 SELinux 属性,因此最终禁用了它......哦,好吧。

Sorry for the late response.
It was to do with SELinux preventing apache to perform calls out to the network. To allow apache to do this, you need to run:

setsebool -P httpd_can_network_connect 1

I was then presented with another related issue where I needed to execute scripts from the command line and couldn't find an appropriate SELinux property so ended up disabling it... ohh well.

王权女流氓 2024-10-11 14:37:00

当您“从命令行执行”时,网络服务器进程很可能不在与您相同的用户下运行,它也可能不具有相同的 shell 环境。
但是,您可以在curl 请求中显式配置代理服务器。如果我没记错的话,它是 -x 开关。你还可以传递很多参数。只需查看联机帮助页即可。
wget 也支持代理,但据我不确定您配置的参数。另请参阅联机帮助页。

the webserver process runs most likely not under the same user as you when you "execute from command line", it will probably not have the same shell environment either.
you can however explicitly configure a proxy server in your curl request. if i recall that correctly its the -x switch. you can also pass a lot of arguments. just see the manpage.
wget supports proxy as well but as far as i am nut sure about the params you configure. see the manpage as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文