Squid反向代理配置示例

这里以Squid for Windows为例,版本为Squid4.14,下载地址https://packages.diladele.com/squid/4.14/squid.msi,配置如下:

# 允许访问的地址范围
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

# 允许访问的安全端口
acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT

# 定义两个(aweb1、aweb2)基于域名的控制列表
acl aweb1 dstdomain 01h.net
acl aweb1 dstdomain www.01h.net
acl aweb2 dstdomain ken.01h.net

# 只允许从本地主机访问cachemgr
http_access allow localhost manager
http_access deny manager

# 拒绝对非安全端口的请求
http_access deny !Safe_ports

# 拒绝连接到安全SSL端口以外的端口
http_access deny CONNECT !SSL_ports

# 允许上面定义的两个基于域名的控制列表(aweb1、aweb2)进行访问
http_access allow aweb1
http_access allow aweb2

# 定义监听端口
http_port 3128 accel vhost vport  # accel 指启用加速(反向代理)模式,vhost、vport 用于转发请求

# 定义两台内网服务器,命名为pweb1、pweb2
cache_peer 192.168.101.237 parent 80 0 no-query originserver name=pweb1
cache_peer 192.168.101.119 parent 80 0 no-query originserver name=pweb2

# 将上面定义的两个控制列表(aweb1、aweb2)分发到对应的内网服务器pweb1、pweb2
cache_peer_access pweb1 allow aweb1
cache_peer_access pweb2 allow aweb2

# 定义缓存目录
coredump_dir /var/cache/squid

# 添加任何您自己的refresh_pattern条目
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0
refresh_pattern .		0	20%	4320

# 配置DNS服务器地址
dns_nameservers 8.8.8.8 202.101.224.69

# 最大文件描述符
max_filedescriptors 3200

# 定义可见主机名
visible_hostname 01H.NET 

说明:基本上所有的注释都写在上面了,如有不懂的地方欢迎留言!

发表评论

邮箱地址不会被公开。 必填项已用*标注