如果想上google,或者其他天朝內無法訪問的網站,怎麼辦呢?前提要有一個,不在大天朝區域網路內的VPS
方法一,搭個vpn,請參考:vpn 安裝配置詳解
方法二,搭個Proxy 伺服器,下面會詳細的說一下
1,安裝squid
# yum install squid
2,添加認證使用者 test123
# htpasswd -c /etc/squid/passwd test123
3,配置代理以及使用者認證
# vim /etc/squid/squid.conf //添加以下內容
auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwd //認證方式為basic,認證程式路徑和密碼檔案路徑
auth_param basic children 5 //認證程式的進程數
auth_param basic credentialsttl 1 hours //認證有效時間
auth_param basic realm my test prosy //瀏覽器顯示輸入使用者/密碼對話方塊時,顯示的內容
acl test123 proxy_auth REQUIRED
http_access allow test123 //普通使用者需要通過認證才能訪問
4,開放防火牆連接埠
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3128 -j ACCEPT //squid預設連接埠,3128
5,重啟squid
# /etc/init.d/squid restart
這樣squid代理就搭好了,瀏覽器裡面設定一下代理IP和連接埠,會彈出認證框,輸入使用者名稱和密碼就行了。
6,php也可以利用Proxy 伺服器
function testCurl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $gurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, "23.220.*.*:3128"); //ip/連接埠
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'test123:123456'); //認證使用者和密碼
$result=curl_exec($ch);
curl_close($ch);
return $result;
}
echo testCurl("google.com");