歡迎您光臨本站 註冊首頁

squid反向代理,總是出現302 不能成功加速

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

squid反向代理,總是出現302 不能成功加速

實驗用到了2台主機,squid版本為squid-2.7.STABLE9
192.168.100.1  cache.madtest.com
192.168.100.20 www.madtest.com


# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               madlinux localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.100.1   cache.madtest.com
192.168.100.20  www.madtest.com

squid的配置文件如下
# cat /usr/local/squid/etc/squid.conf
########## Base control ##########

cache_mgr hellowgw                                 

visible_hostname wgw_squid                           

http_port 0.0.0.0:80 accel vhost http11               

icp_port 0

cache_dir ufs /var/squid 2048 32 256                 

#logformat combined %&gt;a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}&gt;h" %Ss:%Sh        
access_log /var/log/squid/access_log                     

cache_log /var/log/squid/cache_log

cache_store_log none

logfile_rotate 60                                                     

error_directory /usr/local/squid/share/errors/Simplify_Chinese         

unlinkd_program /usr/local/squid/libexec/unlinkd                     

strip_query_terms off                                                  

cache_vary on                                                           

acl apache rep_header Server ^Apache

broken_vary_encoding allow apache

########## Performance control ##########

cache_mem 128 MB                             

cache_swap_low 90

cache_swap_high 95                                                                                 
maximum_object_size 4096 KB

minimum_object_size 0 KB

maximum_object_size_in_memory 2048 KB                              

ipcache_size 2048                                               

ipcache_low 90

ipcache_high 95

cache_replacement_policy lru

memory_replacement_policy lru

log_ip_on_direct on

log_mime_hdrs off

request_header_max_size 64 KB

request_body_max_size 0 KB

negative_ttl 5 minutes            

connect_timeout 1 minute

read_timeout 1 minutes

request_timeout 1 minutes

client_lifetime 30 minutes

half_closed_clients on

maximum_single_addr_tries 1

refresh_pattern -i \.htm$ 1440 90% 129600 reload-into-ims            

refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.shtm$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.xml$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.jpeg$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.gif$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.css$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.swf$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.doc$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.ppt$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.xls$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.pdf$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.cab$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.exe$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.zip$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.dll$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.rar$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.zip$ 1440 90% 129600 reload-into-ims

refresh_pattern -i \.wmv$ 1440 90% 129600 reload-into-ims

refresh_pattern . 1440 80% 9660

acl purge method PURGE

acl QUERY urlpath_regex cgi-bin \?

acl all src all

acl testip src 127.0.0.1/32 192.168.100.0/24

acl testdst dstdomain madtest.com

###### Reverse proxy###########

cache_peer 192.168.100.20 parent 80 0 no-query originserver name=test1

cache_peer_domain test1 www.madtest.com

cache_peer_access test1 allow all

########## Access control ############

http_access allow QUERY

http_access allow purge

http_access allow testdst                              

http_access allow all

cache deny QUERY

hierarchy_stoplist cgi-bin ?

acl CactiServer src 58.210.11.194

acl SNMP snmp_community public                       

snmp_port 3401

snmp_access allow SNMP CactiServer

snmp_access deny all


現在的情況是我通過curl命令測試www.madtest.com的域名,返回的不是200 OK 而是
# curl -I www.madtest.com
HTTP/1.1 302 Found
Date: Wed, 20 Jun 2012 14:49:44 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Location: index_1.php
Connection: close
Content-Type: text/html; charset=GB2312

如果刪除hosts中的域名和IP定義,轉而用額外搭建的DNS定義www.madtest.com這個域名錯誤就會變成
# curl -I www.madtest.com
HTTP/1.1 302 Moved Temporarily
Date: Wed, 20 Jun 2012 14:51:12 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Location: index_1.php
Content-Type: text/html; charset=GB2312
X-Cache: MISS from wgw_squid
Via: 1.1 wgw_squid:80 (squid/2.7.STABLE9)

這是怎麼回事啊,第一次配置squid反向代理死活不成功,請大家幫忙分析一下
《解決方案》

補充一下squid啟動信息
# /usr/local/squid/sbin/squid -NCd1
2012/06/20 18:59:28| Starting Squid Cache version 2.7.STABLE9 for x86_64-unknown-linux-gnu...
2012/06/20 18:59:28| Process ID 6802
2012/06/20 18:59:28| With 65535 file descriptors available
2012/06/20 18:59:28| Using epoll for the IO loop
2012/06/20 18:59:28| Performing DNS Tests...
2012/06/20 18:59:28| Successful DNS name lookup tests...
2012/06/20 18:59:28| helperOpenServers: Starting 5 'dnsserver' processes
2012/06/20 18:59:29| logfileOpen: opening log /var/log/squid/access_log
2012/06/20 18:59:29| Unlinkd pipe opened on FD 15
2012/06/20 18:59:29| Swap maxSize 2097152 + 131072 KB, estimated 171401 objects
2012/06/20 18:59:29| Target number of buckets: 8570
2012/06/20 18:59:29| Using 16384 Store buckets
2012/06/20 18:59:29| Max Mem  size: 131072 KB
2012/06/20 18:59:29| Max Swap size: 2097152 KB
2012/06/20 18:59:29| Store logging disabled
2012/06/20 18:59:29| Rebuilding storage in /var/squid (DIRTY)
2012/06/20 18:59:29| Using Least Load store dir selection
2012/06/20 18:59:29| Current Directory is /root
2012/06/20 18:59:29| Loaded Icons.
2012/06/20 18:59:30| Accepting accelerated HTTP connections at 0.0.0.0, port 80, FD 16.
2012/06/20 18:59:30| Accepting SNMP messages on port 3401, FD 17.
2012/06/20 18:59:30| WCCP Disabled.
2012/06/20 18:59:30| Configuring test1 Parent test1/80/0
2012/06/20 18:59:30| Ready to serve requests.
2012/06/20 18:59:30| Done reading /var/squid swaplog (137 entries)
2012/06/20 18:59:30| Finished rebuilding storage from disk.
2012/06/20 18:59:30|        94 Entries scanned
2012/06/20 18:59:30|         0 Invalid entries.
2012/06/20 18:59:30|         0 With invalid flags.
2012/06/20 18:59:30|        94 Objects loaded.
2012/06/20 18:59:30|         0 Objects expired.
2012/06/20 18:59:30|        43 Objects cancelled.
2012/06/20 18:59:30|         0 Duplicate URLs purged.
2012/06/20 18:59:30|         0 Swapfile clashes avoided.
2012/06/20 18:59:30|   Took 0.5 seconds ( 194.7 objects/sec).
2012/06/20 18:59:30| Beginning Validation Procedure
2012/06/20 18:59:30|   Completed Validation Procedure
2012/06/20 18:59:30|   Validated 51 Entries
2012/06/20 18:59:30|   store_swap_size = 1696k
2012/06/20 18:59:30| storeLateRelease: released 0 objects

請大家幫幫忙!!
《解決方案》

自己結貼,由於我測試的網站代碼主要是由php寫的,所以出現不能代理的情況。但是從後台看日誌可以發現網站上的圖片已經被成功HIT了。說明配置的沒問題。是網站開發語言的問題。
《解決方案》

你把訪問日誌貼出來看看就知道了。還有,貌似curl不能隨,wget可以發起第二次請求

[火星人 ] squid反向代理,總是出現302 不能成功加速已經有744次圍觀

http://coctec.com/docs/service/show-post-12703.html