麒麟系统最简squid配置文件

2025年4月12日

/etc/squid/squid.conf

# 双栈监听基础配置
http_port 3128
http_port 0.0.0.0:3128 # IPv4监听
http_port [::]:3128 # vhost # IPv6监听‌:ml-citation{ref=”6″ data=”citationList”}
visible_hostname squid-cache-proxy
dns_v4_first on

# 缓存存储配置(调整路径和容量)
cache_dir aufs /data/usershare/squid_cache 100000 16 256 # 50GB存储空间‌:ml-citation{ref=”1″ data=”citationList”}
maximum_object_size 4096 MB # 允许缓存大文件‌:ml-citation{ref=”6″ data=”citationList”}
minimum_object_size 0 KB # 不限制最小文件
maximum_object_size_in_memory 512 MB
cache_mem 512 MB # 内存缓存空间‌:ml-citation{ref=”1″ data=”citationList”}

# IPv4/IPv6访问控制
acl ipv4_clients src all
acl ipv6_clients src ::/0
http_access allow ipv4_clients
http_access allow ipv6_clients

# 强制缓存所有内容
#acl CACHEABLE_OBJECTS url_regex .*
#cache allow CACHEABLE_OBJECTS
#cache deny all

acl cacheable_objects2 url_regex -i \.(jpg|jpeg|png|gif|css|js|html|mp3|mp4|bmp|exe|zip|rar|iso|7z|php|asp|aspx|shtml|htm|docx|xlsx|wps|pptx|doc|mov|wav|xls)$
http_reply_access allow cacheable_objects2
#http_reply_access deny all

# 允许缓存所有 HTTP 方法(GET/POST/HEAD等)
acl ALLOWED_METHODS method GET POST HEAD PUT
http_access allow ALLOWED_METHODS

# 允许缓存所有文件类型和动态内容
refresh_pattern . 0 100% 4320 override-expire override-lastmod ignore-reload ignore-no-store

# 强制缓存所有响应(即使服务器声明不缓存)
acl CACHEABLE_OBJS rep_header Cache-Control !no-cache
cache allow CACHEABLE_OBJS

# 全局缓存策略(24小时强制过期)
refresh_pattern ^.*$ 1440 100% 1440 override-expire override-lastmod reload-into-ims ignore-no-store ignore-private

# ‌:ml-citation{ref=”3,6″ data=”citationList”}
# 强制缓存策略
#refresh_pattern ^.*$ 0 100% 1440 override-expire override-lastmod ignore-no-store ignore-private reload-into-ims‌:ml-citation{ref=”3,4″ data=”citationList”}

# 访问控制
acl all_clients src all
http_access allow all_clients

# 日志与维护
access_log daemon:/data/usershare/squid_cache/access.log squid
cache_log /data/usershare/squid_cache/cache.log
cache_swap_low 90
cache_swap_high 95

# 性能优化
max_filedescriptors 65535
half_closed_clients off
read_timeout 15 minutes
client_persistent_connections on

# 安全设置
#request_header_access Via deny all
#reply_header_access Server deny all
#visible_hostname squid6-proxy

#验证与维护命令:
# 初始化缓存目录
#sudo squid -z -N -f /etc/squid/squid.conf
# 测试配置有效性
#squid -k parse
# 强制刷新所有缓存(紧急情况)
#squidclient -m PURGE -p 3128 ‘.*’

 

折腾了三天,终于搞明白了这个,支持IPV6,支持全部网页缓存的。