代理服务器分正向代理 和 反向代理
正向代理设置
yum install squid
vim /etc/squid/squid.conf
cache_dir ufs /var/spool/squid 100 16 256 去掉该行前面注释的 并添加
cache_mem 28 MB
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
# Add any of your own refresh_pattern entries above these.
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
refresh_pattern \.(jpg|png|gif|js|css|mp3|mp4) 1440 20% 2880 ignore-reloadvisible_hostname localhost
保存退出启动服务
查看监听端口
netstat -lnp
默认 3128
在浏览器设置代理后 可以监听网卡
tcpdump -i eth3 -nn port 3128
也可以查看缓存
cd /var/spool/squid/
可以在配置文件内修改端口
使用alc语句禁止或者允许代理访问
acl CONNECT method CONNECT
acl http proto HTTP
acl good_domain dstdomain .lishiming.net .aminglinux.com
http_access allow good_domain
http_access deny !good_domain
:wq 仅仅允许访问阿铭linux网站
squid -kcheck 检查
squid -kre 加载
反向代理设置
修改配置文件端口至
80
# Squid normally listens to port 3128
http_port 80 accel vhost vport
cache_peer 180.97.33.108 parent 80 0 originserver name=a
cache_peer_domain a www.baidu.com
#cache_peer 180.97.33.108 parent 80 0 originserver name=a
#cache_peer_domain a www.baidu.com
以上填写服务信息即可
解除nginx 对80端口的占用
重启squid
在本地host文件添加域名指向