天天看點

代理伺服器

部署代理伺服器:http代理伺服器(squid程式)

主機1部書squid代理伺服器:

1、在主機1上安裝squid

root@linux_ever:~# apt-get install squid

2、修改squid的配置檔案squid.conf

root@linux_ever:~# gedit /etc/squid/squid.conf

定位到下面的位置,将http_access deny deny 改為 http_access allow all

# And finally deny all other access to this proxy

http_access deny all #這裡把deny改成allow就可以讓任意使用者通過你的機器作為代理了</span>

或者将上面的http_access deny deny替換為下面的兩行(本次使用的這種配置)

acl localnet src 192.168.1.0/24

http_access allow localnet</span>

這兩行的意思是允許192.168.0.0網絡上的所有機器通過該代理伺服器來通路Web伺服器。192.168.0.0/24表明,/之前的網絡位址,/之後的24表明子網路遮罩中1的位數,這種寫法等價于192.168.1.0/255.255.255.0

3、重新開機squid伺服器

root@linux_ever:~# service squid restart

還有下面兩個指令:

root@linux_ever:~# service squid start 啟動運作

root@linux_ever:~# service squid stop 停止運作

service是一個腳本程式(/usr/sbin/service),它為/etc/init.d/目錄下的衆多伺服器程式(httpd, vsftpd, sshd, mysqld等)的啟動(start)、停止(stop)、重新開機(restart)等動作提供了一個統一的管理。

主機2可以測試驗證主機1的代理服務:

第一步:在主機2上配置環境變量http_proxy,輸入指令:export http_proxy="192.168.0.141:3128" 其中192.168.0.141是主機1的IP位址

第二步:執行wget用戶端獲得百度的首頁,輸入指令:wget http://www.baidu.com/index.html

輸出為:

root@linux_ever2:~# wget http://www.baidu.com/index.html

--2016-01-15 19:18:28-- http://www.baidu.com/index.html

正在連接配接 192.168.0.141:3128... 已連接配接。

已發出 Proxy 請求,正在等待回應... 200 OK

長度: 未指定 [text/html]

正在儲存至: “index.html”

繼續閱讀