欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CentOS上使用Squid+Stunnel搭建代理服務(wù)器教程

海底蒼鷹(tank)博客   發(fā)布時(shí)間:2015-12-31 12:05:23   作者:海底蒼鷹   我要評論
這篇文章主要介紹了CentOS上使用Squid+Stunnel搭建代理服務(wù)器教程,同時(shí)文中也介紹了用戶認(rèn)證的方法,適合于多用戶共同使用代理,這種功能在國內(nèi)用還是比較exciting的~需要的朋友可以參考下

代理服務(wù)器,就不用介紹了,簡單說一下安裝過程。開始的時(shí)候在hosting24上面,安裝,怎么安裝都沒有成功,換成linode,半個(gè)小時(shí)就搞定了,猜測hosting24對代理做了限制。
一,服務(wù)器說明
一臺國外的vps(推薦linode),服務(wù)端squid
一臺公司內(nèi)部的PC機(jī),能訪問外網(wǎng)就行,客戶端stunnel
要達(dá)到的目的,公司內(nèi)部人員,連接公司內(nèi)部的pc機(jī),通過stunnel通道連接遠(yuǎn)端squid,上外網(wǎng)查資料,谷歌,眾里尋你千百度,驀然回首你卻在高墻外頭。唉。


二,服務(wù)端安裝squid
1,安裝squid

復(fù)制代碼
代碼如下:

# yum install squid openssl openssl-devel

2,生成加密代理證書

復(fù)制代碼
代碼如下:

# cd /etc/squid
# openssl req -new > tank.csr //要求輸入密碼和確認(rèn)密碼
# openssl rsa -in privkey.pem -out tank.key //輸入上面輸入的密碼
# openssl x509 -in tank.csr -out tank.crt -req -signkey tank.key -days 3650

3,配置squid

復(fù)制代碼
代碼如下:

# vim /etc/squid/squid.conf

acl OverConnLimit maxconn 10 //限制每個(gè)IP最大允許10個(gè)連接,防止攻擊
minimum_object_size 1 KB //允午最小文件請求體大小
maximum_object_size 1 MB //允午最大文件請求體大小
cache_swap_low 10 //最小允許使用swap 10%
cache_swap_high 25 //最大允許使用swap 25%
cache_mem 300 MB //可使用內(nèi)存

/*****************上面是新增,下面是修改************************/

cache_dir ufs /var/spool/squid 2048 16 256 //2048存儲空間大小,一級目錄16個(gè),二級256個(gè)
https_port 4430 cert=/etc/squid/tank.crt key=/etc/squid/tank.key //端口可自定義
http_access allow all

vps硬盤,內(nèi)存都不富裕,所以對squid所占用的內(nèi)存和硬盤等要加以控制。
4,啟動squid,并查看

復(fù)制代碼
代碼如下:

# /etc/init.d/squid start

# ps aux |grep squid
root 15984 0.0 0.0 103256 844 pts/0 S+ 17:31 0:00 grep squid
root 16585 0.0 0.0 72484 4176 ? Ss 15:27 0:00 squid -f /etc/squid/squid.conf
squid 16587 0.0 0.3 93064 29468 ? S 15:27 0:03 (squid) -f /etc/squid/squid.conf
squid 16589 0.0 0.0 48632 2100 ? S 15:27 0:00 (ncsa_auth) /etc/squid/passwd
squid 16590 0.0 0.0 48632 1788 ? S 15:27 0:00 (ncsa_auth) /etc/squid/passwd
squid 16591 0.0 0.0 48632 1784 ? S 15:27 0:00 (ncsa_auth) /etc/squid/passwd
squid 16592 0.0 0.0 48632 1788 ? S 15:27 0:00 (ncsa_auth) /etc/squid/passwd
squid 16593 0.0 0.0 48632 1784 ? S 15:27 0:00 (ncsa_auth) /etc/squid/passwd
squid 16594 0.0 0.0 20084 1112 ? S 15:27 0:00 (unlinkd)

VPS很少有,自啟動開啟防火墻的,如果有先關(guān)掉,等都配置好了,在開放端口。


三,客戶端安裝配置stunnel
1,安裝

復(fù)制代碼
代碼如下:

# yum install stunnel

2,新增配置/etc/stunnel/stunnel.conf,添加以下內(nèi)空

復(fù)制代碼
代碼如下:

client = yes
fips = no
[https]
accept = 7071
connect = 外網(wǎng)VPS的IP:4430

如果報(bào),F(xiàn)IPS_mode_set: 2D06C06E: error:2D06C06E:FIPS routines:FIPS_module_mode_set:fingerprint does not match,stunnel.conf配置文件中加上,fips = no
3,啟動stunnel并查看

復(fù)制代碼
代碼如下:

# stunnel //啟動,默認(rèn)配置文件路徑 /etc/stunnel/stunnel.conf

# ps aux |grep stunnel //查看
root 15972 0.0 0.0 103256 848 pts/0 S+ 17:30 0:00 grep stunnel
root 21099 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21100 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21101 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21102 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21103 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel
root 21104 0.0 0.0 2077984 6824 ? Ss 15:42 0:00 stunnel

到這兒就安裝好了,設(shè)置瀏覽器代理,填寫局域網(wǎng)IP和端口,就可以訪問外網(wǎng)了,這樣不太安全,如果能加上用戶認(rèn)證會,安全一點(diǎn)。

四,用戶認(rèn)證
1,添加認(rèn)證用戶 test123

復(fù)制代碼
代碼如下:

# htpasswd -c /etc/squid/passwd test123

2,配置代理以及用戶認(rèn)證

復(fù)制代碼
代碼如下:

# vim /etc/squid/squid.conf //添加以下內(nèi)容

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwd //認(rèn)證方式為basic,認(rèn)證程序路徑和密碼文件路徑
auth_param basic children 5 //認(rèn)證程序的進(jìn)程數(shù)
auth_param basic credentialsttl 1 hours //認(rèn)證有效時(shí)間
auth_param basic realm my test prosy //瀏覽器顯示輸入用戶/密碼對話框時(shí),顯示的內(nèi)容
acl test123 proxy_auth REQUIRED
http_access allow test123 //普通用戶需要通過認(rèn)證才能訪問
http_access deny all //最下面,匹配是從上到下的

3,重啟squid

復(fù)制代碼
代碼如下:

# /etc/init.d/squid restart

這樣squid代理就搭好了,瀏覽器里面設(shè)置一下代理IP和端口,會彈出認(rèn)證框,輸入用戶名和密碼就行了。
4,php也可以利用代理服務(wù)器

復(fù)制代碼
代碼如下:

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, "192.168.1.18:7071"); //ip/端口
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'test123:123456'); //認(rèn)證用戶和密碼
$result=curl_exec($ch);
curl_close($ch);
return $result;
}

echo testCurl("google.com");
 

相關(guān)文章

最新評論