安装
yum install squid -y yum install httpd-tools -y
生成密码文件
mkdir /etc/squid3/ #这里密码是 ceshi htpasswd -cd /etc/squid3/passwords ceshi #回车 自己输入密码
测试密码文件
/usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords #输入账号跟密码 ceshi 123456 #提示 ok 代表正确 ok
配置
vim /etc/squid/squid.conf # 在最后添加 auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords auth_param basic realm proxy acl authenticated proxy_auth required http_access allow authenticated # 这里是端口号,可以按需修改 # http_port 3128 这样写会同时监听ipv6和ipv4的端口,推荐适应下面的配置方法。 http_port 0.0.0.0:3128
启动服务
# 开启启动 systemctl enable squid.service # 启动 systemctl start squid.service # 停止 systemctl stop squid.service # 重启 systemctl restart squid.service
配置副本–无权限控制
# # recommended minimum configuration: # # example rule allowing access from your local networks. # adapt to list your (internal) ip networks from where browsing # should be allowed 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 many_spaces rep_header disposition -i [k123] acl connect method connect # # recommended minimum access permission configuration: # # deny requests to certain unsafe ports #http_access allow all !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 #http_access allow all http_access allow all auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords auth_param basic realm proxy acl authenticated proxy_auth required #http_access allow authenticated # and finally deny all other access to this proxy http_access allow all # squid normally listens to port 3128 http_port 0.0.0.0: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
配置副本-权限控制
# # recommended minimum configuration: # # example rule allowing access from your local networks. # adapt to list your (internal) ip networks from where browsing # should be allowed 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 many_spaces rep_header disposition -i [k123] acl connect method connect # # recommended minimum access permission configuration: # # deny requests to certain unsafe ports #http_access allow all !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 #http_access allow all #http_access allow all auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords auth_param basic realm proxy acl authenticated proxy_auth required http_access allow authenticated #http_access allow many_spaces # and finally deny all other access to this proxy http_access deny all # squid normally listens to port 3128 http_port 0.0.0.0: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
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论