代理网站(如kproxy)的内部实现

代理网站(如kproxy)的内部实现,proxy,http-proxy,proxy-server,webproxy,Proxy,Http Proxy,Proxy Server,Webproxy,我想实现像kproxy.com这样的代理网站,这样我就可以在我的网站的iframe中加载任何网站,并从我的服务器代理网站的所有数据 我检查了它们的功能,发现它们替换了所有脚本标记、链接(css)标记和图像标记,以从服务器获取内容 例如,如果原始网站包含标签,如 <script src="http://google.com/abc.js"></script> 他们将用 <script src="http://kproxy.com/redirect/foo/bar

我想实现像kproxy.com这样的代理网站,这样我就可以在我的网站的iframe中加载任何网站,并从我的服务器代理网站的所有数据

我检查了它们的功能,发现它们替换了所有脚本标记、链接(css)标记和图像标记,以从服务器获取内容

例如,如果原始网站包含标签,如

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

他们将用

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

我通过替换所有节点来实现这种功能,这样就可以通过我的服务器代理它们

但是现在问题仍然存在于ajax调用中,ajax调用将由javascript发起并调用原始服务器,因此在我的iframe中,有时会出现
“x-frame-options=SAMEORIGIN”
错误


那么,我能做些什么来获得与kproxy相同的功能呢?并且只代理通过我的服务器的所有流量。

您的问题源于一些指向不同域的链接(可能是AJAX链接)

您应该检查您下载的脚本,以便在运行时生成URL,如

...a="https:"==g.location.protocol?"https://csi.gstatic.com/csi":"http://csi.gstatic.com/csi");return...
(示例取自谷歌分析)。一些jQuery小程序也是如此

此外,您还应该验证一些脚本没有自己进行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

您当前使用的web服务器是什么?@SteveSiebert我当前使用的是IIS 8.0