2014-10-20 45 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