2014-10-20 106 views
0

代理网站,我要实现的代理网站像kproxy.com,这样我可以在我的网站的iframe和代理从我的服务器加载任何网站网站的所有数据内部实现像kproxy

我已签他们的功能,我发现他们取代所有的脚本标签,链接(CSS)标签和图像标签,以从他们的服务器获取内容。如果原始网站包含了诸如

<script src="http://google.com/abc.js"></script> 

标签,他们将与

<script src="http://kproxy.com/redirect/foo/bar/abc.js"></script> 

我已经完成了这种功能与替换所有节点,所以它们可以通过我的服务器

但现在被代理更换问题仍然存在与ajax调用,这将由JavaScript发起,并将调用原始服务器,所以在我的iframe我有时会得到"x-frame-options = SAMEORIGIN"错误

那么,我能做些什么像kproxy一样的功能呢?并仅通过我的服务器代理所有流量。

+0

你目前使用什么网络服务器? – 2014-11-04 06:08:51

+0

@SteveSiebert我目前使用IIS 8.0 – 2014-11-04 06:11:57

回答

1

你的问题来自一些链接(可能是AJAX的)正在向不同的领域产生。

您应该检查你下载的脚本的URL在运行时被建立像

...a="https:"==g.location.protocol?"https://csi.gstatic.com/csi":"http://csi.gstatic.com/csi");return... 

(从谷歌Analytics(分析)所采取的示例)。一些jQuery applet也是如此。

此外,您应该验证一些脚本不会自己调用AJAX来检索更多的URL。如果他们这样做,则需要检查是否要代理这些呼叫。

基本上,对于每次致电给您的同源故障,您需要跟踪它从哪里来,并指示您的代理识别并重写它

或者您可以尝试在Javascript中执行相同的操作,即注入Javascript代码,以便在运行时重写这些URL。例如,你可以有明确的检查,比如说,CKEditor

// client requested a script and you, the proxy, fetched it in 'script' 
if (script contains 'CKEDIT.options') { 
    determine init call position in script 
    split the script in two, A and B, before and after the init call 
    make 'script' equal to a new script made up of B plus C plus A concatenated 
    where C is the line "CKEDIT.options.url = 'http://mysite/proxy...';\n" 
    so that, user side, the initialization will happen with your site's address 
    The script will then propagate that address in lots of places without need 
    for you to rewrite anything else. 
} else { 
    // script is unmodified 
} 
... other checks like the above... 

... finally: 
send 'script' to the client