天天看點

Squid代理權限的設定

本人隻介紹Squid代理權限的設定,若是安裝的話,可以參考

<a href="http://fengwan.blog.51cto.com/508652/1212613" target="_blank">http://fengwan.blog.51cto.com/508652/1212613</a>

在很多公司裡面上網都是控制的相當嚴格,那麼我們通過下面幾個執行個體來抛磚引玉:

 說明:由于我的squid是使用yum的方式安裝的,如果你是手動編譯的話,請更改相應的設定

1.某幾個IP上網不受限制(如192.168.1.10和192.168.1.20這個IP上網不受限制)

編輯vim /etc/squid/squid.conf

在前面加入以下字段:

acl master src 192.168.1.10/32 192.168.1.20/32

http_access allow master

2.某幾個IP隻能上某個網站(如192.168.1.12隻能通路www.baidu.com)

acl web_ctrl src 192.168..1.12/32

acl web_ctrl_url url_regex www.baidu.com //若是增加網站的話隻需在後面添加網址即可 

acl allow web_ctrl web_ctrl_url

3.某幾個IP限制時間上網(如192.168.1.15上班時間隻能上公司網站,下班後可以上其他網站)

acl time_client src 192.168.1.15/32                     //定義客戶機位址

acl time_time time MTWHF 08:00-12:00 13:00-17:00     //在星期一到星期五的8點到12點 13點到17點

acl time_server url_regex lookwest.taobao.com          //設定要通路的網站

http_access allow time_client time_time time_server    //允許192.168.1.15上班時間上www.lushare.com

http_access deny time_time                           //拒絕上班時間的通路,防止上其他網站

http_access allow time_client                           //允許192.168.1.15上網

4.其他電腦需要使用使用者名和密碼才能上網,主要是用于臨時使用網絡

a.首先需要生成一個密碼檔案

[root@WebSer ~]# htpasswd -c /etc/squid/user.pass lookwest

New password:

Re-type new password:

Adding password for user lookwest

上面就已經增加了一個lookwest帳戶

htpasswd的用法:

1.增加使用者

htpasswd  /etc/squid/user.pass lookwest

2.修改使用者密碼:

htpasswd -d /etc/squid/user.pass lookwest

3.删除使用者:

htpasswd -D /etc/squid/user.pass lookwest

b.編輯/etc/squid/squid.conf

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/user.pass

//由于我使用的是64位的centos是以上面是/usr/lib64/squid/ncsa_auth

//那後面跟的就是剛才生成密碼檔案的位置/etc/squid/user.pass

auth_param basic children 5

//指定認證程式的程序數

auth_param basic realm Welcome to LookWest

//浏覽器顯示輸入使用者/密碼對話框時的領域内容 

auth_param basic credentialsttl 2 hours

//基本的認證有效時間

acl lookwest proxy_auth REQUIRED

//普通使用者需要通過認證才能通路Internet

http_access allow lookwest

最後需要加入一行:

http_access deny all   

小技巧:

要使squid重新加載配置檔案是不用重新啟動squid服務的,隻需要運作:

[root@WebSer ~]# squid -k reconfigure

本文轉自 rong341233 51CTO部落格,原文連結:http://blog.51cto.com/fengwan/1248026

繼續閱讀