Squid 正向代理

 

實現經過特定設備對特定的網址訪問加速python

使用squid 正向代理 實現,區別於反向代理,二者區別的根本在於做爲中轉的服務器在一個完整的請求中是表明客戶端仍是表明服務器。web

服務端設置

1.安裝程序包(推薦 Centos 6.8 7.2)

sudo yum update
sudo yum -y install squid

2.關閉干擾程序

chkconfig --level 2345 postfix off
chkconfig --level 2345 sendmail off

3.設置緩存目錄(建議設置大一點的)

mkdir -p /var/cache/squid
chown -R squid:squid / /var/cache/squid
#chmod -R 777 /var/cache/squid 
#不到萬不得已 不要設置 777

4.啓動測試

squid -z 
#檢查配置文件
service squid restart
#centos 6
systemctl restart squid.service
#centos 7
chkconfig --level 2345 squid on

通過以上幾個步驟 若是沒有端口衝突 能夠肯定 squid 啓動沒有問題。說明squid 的啓動環境OK,下面將對咱們的需求作指定調整chrome

配置文件:

 1 acl xxx-v-szzb dst 127.0.0.0/8 0.0.0.0/32 ::1
 2 acl SSL_ports port 443
 3 acl Safe_ports port 80      # http
 4 acl Safe_ports port 21      # ftp
 5 acl Safe_ports port 443     # https
 6 acl Safe_ports port 70      # gopher
 7 acl Safe_ports port 210     # wais
 8 acl Safe_ports port 1025-65535  # unregistered ports
 9 acl Safe_ports port 280     # http-mgmt
10 acl Safe_ports port 488     # gss-http
11 acl Safe_ports port 591     # filemaker
12 acl Safe_ports port 777     # multiling http
13 acl CONNECT method CONNECT
14 
15 http_access allow manager xxx-v-szzb
16 http_access deny manager
17 http_access deny !Safe_ports
18 http_access deny CONNECT !SSL_ports
19 #http_access allow all 
20 #acl http proto HTTP
21 acl good_domain dstdomain .salesforce.com .force.com .ip508.com
22 http_access allow manager good_domain
23 http_access deny !good_domain
24 
25 http_port 80
26 coredump_dir /app/squid/coredump_dir1
27 refresh_pattern ^ftp:       1440    20% 10080
28 refresh_pattern ^gopher:    1440    0%  1440
29 refresh_pattern -i (/cgi-bin/|\?) 0 0%  0
30 refresh_pattern (Release|Packages(.gz)*)$      0       20%     2880
31 refresh_pattern .       0   20% 4320
32 strip_query_terms off
33 visible_hostname ss.72blog.com
34 cache_store_log none
35 cache_access_log none
36 cache_mem 512 MB
37 cache_dir aufs /app/squid/cache_dir1 5000 128 128
38 cache_swap_low 90
39 cache_swap_high 95
40 maximum_object_size 128 MB
41 maximum_object_size_in_memory 128 MB
42 dns_nameservers 10.0.1.1 10.0.1.2
43 client_lifetime 1 minutes
44 half_closed_clients off

不可照搬,有如下幾行須要自定義

1/15:兩行的主機名要是 squid所在設備的主機名centos

2~12 :設置接受的代理端口 瀏覽器

13~30:落實上述端口的設置,不在端口類的,不作代理緩存

21~23:設置代理的目的域名,不在範圍的目的域名不作代理,這裏配置了三個,【.ip508.com用來測試代理是否生效的(能夠返回客戶端IP)】bash

25:設置端口服務器

26~40:在不清楚意義的前提下,不要修改,【26/37 緩存目錄須要修改】app

客戶端設置

不可在IE設置全局,由於IE瀏覽器設置後致使整個操做系統全局訪問被設置dom

Chrome

1.快捷方式設置

直接找到chrome 的快捷方式加上啓動配置

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
#這是原配置
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="172.31.2.35:80"
#這是新配置 加上  --proxy-server="172.31.1.135:80"

可是這樣配置的結果就是致使 chrome 被全局設置了,chrome 只能訪問 squid 配置文件 21 行配置的地址。

2.插件配置

安裝插件:Proxy Switchy!

配置插件

配置規則

 

 選擇自動切換模式,這樣只有特定的地址纔會走代理,而服務端只能代理這些特定的地址。

相關文章
相關標籤/搜索