通过 HTTP 代理的 Apachecurl
我正在尝试让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉回复晚了。
这是因为 SELinux 阻止 apache 执行对网络的调用。为了允许 apache 执行此操作,您需要运行:
然后我遇到了另一个相关问题,我需要从命令行执行脚本,但找不到合适的 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:
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.
当您“从命令行执行”时,网络服务器进程很可能不在与您相同的用户下运行,它也可能不具有相同的 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.