@SurJuzi

文章 分类 评论
45 7 2

站点介绍

这里是站点介绍...

Centos Linux 上安装和配置Squid代理服务配置用户和密码

admin 2023-10-30 163 0条评论 技术教程 linux

首页 / 正文
站点公告

发布于2023-09-02

介绍

Squid 是一个功能齐全的缓存代理,支持流行的网络协议,如 HTTP , HTTPS , FTP 等。它可用于通过缓存重复请求,过滤 Web 流量和访问地域限制内容来提高 Web 服务器的性能。
在本教程中,我们将解释如何在 Debian Buster 上设置 Squid 代理。我们还将向您展示如何配置 Firefox 和 Google Chrome 网络浏览器以使用它。

squid安装方式

yum install squid

配置squid

重要文件
/etc/squid/squid.conf 是squid的配置文件
/var/log/squid/access.log 是访问日志
打开/etc/squid/squid.conf 文件并配置内容如下
#
# Recommended minimum configuration:
#
 
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
# 配置localnet的局域网段下面是localnet 能映射的网段
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
# 本人本机是192.168.50.24,然后代理访问时想不被局域网拦截,从而需要用户密码认证,所以我注释了这里
# 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
 
#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
 
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
 
# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
 
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
 
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
 
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
# allow是允许局域网代理访问(localnet映射的网址在上面 acl localnet那一堆默认的)
http_access allow localnet
http_access allow localhost
 
# 这三行是个人配置的代理访问用户和密码
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user
 
# And finally deny all other access to this proxy
http_access deny all
 
# Squid normally listens to port 3128
http_port 3128
 
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
 
# 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

用户密码认证配置方式如下

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user

这里需要注意!!!切勿将这三行配置放在 refresh_pattern配置下面,否则会失效(本人就是稀里糊涂的放在文件最下面,最终不知道哪里出错,网上很多资料误导放置最下面,导致花费了大量时间排查问题)

/etc/squid/passwd 是用户密码存储文件,密码是经过加密的
可使用如下命令来生成用户密码
htpasswd -c /etc/squid/passwd 用户名

(没有htpasswd可安装yum install httpd-tools)

重启命令,注意先放开安全组或流量端口3128

systemctl restart squid

curl 测试进行代理访问

curl -x http_proxy://用户:密码@192.168.50.132:3128 www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html>

文章出处

评论(0)