Joomla站点在LAMP服务器后面代理无法访问HTTP资源流 [英] Joomla site on LAMP server behind proxy cannot access HTTP resource stream

查看:205
本文介绍了Joomla站点在LAMP服务器后面代理无法访问HTTP资源流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装程序:
1. LAMP服务器上的Joomla 1.5网站(CentOS 5.2 / Apache 2.2 / PHP 5.2.9 / mysql 5)
2.添加用于货币转换的Joomla模块。模块使用google finance转换货币
3.LAMP堆栈位于代理后面的内部网。已设置http_proxy,yum.conf代理的服务器环境变量,并且内核已成功更新。
4. phpinfo()清楚地显示curl已安装
5.在2.中提到的模块允许3种方法连接到google finance,fread(),file_get_contents()和使用cURL库。因为框在代理后面,只有cURL库方法应该工作。



问题:
在WAMP堆栈,curl库方法工作正常。然而,在灯堆栈,模块无法与谷歌财务进行通信,并引发一个错误提及连接超时。

  if(isset($ _ GET ['process'])){
$ url =http://finance.google.com/finance/converter?a= {
$ _GET ['a']}& from = {$ _ GET ['from']}& to = {$ _GET ['to']};
$ app-> get_page($ url);
$ data = $ app-> process();
}

function get_page($ url){
if($ url!=''){
echo $ url;
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ ch,CURLOPT_BINARYTRANSFER,$ this-> binary);
$ this-> html = curl_exec($ ch);
curl_close($ ch);
}
}



我甚至尝试添加curl_setopt($ ch,CURLOPT_PROXY ,'10.x.xx.xx:8080');后curl_init(),无效。我编译apache与libcurl和php启用,我需要知道以下:
1.如何指示php通过代理路由传出请求(流)?
2.我需要用代理名和端口配置cURL(libcurl)吗?
3.我已经切换iptables关闭,所以linux防火墙不再在图片中,有没有其他我需要做,以允许传出请求?
4.我设置了代理,使我的LAMP堆栈为所有内容解除阻塞,cURL在命令行工作,但不是从php / apache。我缺少什么?任何环境变量?任何开关?



预先感谢您的时间。



Shrinivas



 <$ c $ 

c><?php
$ url ='www.whatismyip.com/automation/<your unique whatismyip hash>';

function get_page($ url,$ proxy = true){
if($ url!=''){
$ ch = curl_init
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true);
if($ proxy){
curl_setopt($ ch,CURLOPT_PROXY,'localhost');
curl_setopt($ ch,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
curl_setopt($ ch,CURLOPT_PROXYPORT,1090);
}
$ html = curl_exec($ ch);
curl_close($ ch);
return $ html;
}
}


var_dump(get_page($ url));
var_dump(get_page($ url,false));

您可能想使用 curl_setopt($ ch,CURLOPT_PROXYTYPE,CURLPROXY_HTTP ); curl_setopt($ ch,CURLOPT_PROXYPORT,8080);


Setup: 1. Joomla 1.5 website on a LAMP server (CentOS 5.2/Apache 2.2/PHP 5.2.9/mysql 5) 2. Joomla module for currency conversion added. Module uses google finance to convert currency 3. LAMP stack resides in the intranet behind a proxy. The server environment variables for http_proxy, yum.conf proxy have been setup, and kernel successfully updated. 4. phpinfo() clearly shows curl is installed 5. module mentioned in '2.' allows 3 methods to connect to google finance, fread(), file_get_contents() and using the cURL libraries. As the box is behind a proxy, only the cURL libraries method should work.

Problem: on a WAMP stack, the curl library method works fine. On the lamp stack, however, the module is unable to communicate with google finance, and throws an error mentioning connect timed out. Here's some code to make it clearer.

if (isset($_GET['process'])) {        
$url = "http://finance.google.com/finance/converter?a={
$_GET['a']}&from={$_GET['from']}&to={$_GET['to']}";
$app->get_page($url);
$data = $app->process();
}  

function get_page($url) {
if ($url!='') {
echo $url;
$ch = curl_init ();
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    curl_setopt($ch, CURLOPT_URL, $url);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                    curl_setopt($ch, CURLOPT_BINARYTRANSFER, $this->binary);
                    $this->html = curl_exec($ch);
                    curl_close($ch);
            }
    }

I even tried adding a curl_setopt($ch, CURLOPT_PROXY,'10.x.xx.xx:8080'); after curl_init(), to no avail. I've compiled apache with libcurl and php enabled, and I need to know the following: 1. How to instruct php to route outgoing requests(streams) through the proxy? 2. Do I need to configure cURL (libcurl) with the proxyname and port? 3. I've switched iptables off, so the linux firewall is not in the picture anymore, is there anything else I need to do to allow outgoing requests? 4. I've setup the proxy so that my LAMP stack is unblocked for all content, cURL works off the command line, but not from php/apache. What am I missing? Any environment variables? Any switches?

Thanks in advance for your time.

Shrinivas

解决方案

Here's an example using a local SOCKS5 proxy on port 1090:

<?php
$url = 'www.whatismyip.com/automation/<your unique whatismyip hash>';

function get_page($url, $proxy=true) {
    if ($url!='') {
        $ch = curl_init ();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        if ($proxy) {
            curl_setopt($ch, CURLOPT_PROXY, 'localhost');
            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
            curl_setopt($ch, CURLOPT_PROXYPORT, 1090);
        }
        $html = curl_exec($ch);
        curl_close($ch);
        return $html;
    }
}


var_dump(get_page($url));
var_dump(get_page($url, false));

You'd probably want to use curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); and curl_setopt($ch, CURLOPT_PROXYPORT, 8080); instead.

这篇关于Joomla站点在LAMP服务器后面代理无法访问HTTP资源流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆