本文为作者学习文章,按作者习惯写成,如有错误或需要追加内容请留言(不喜勿喷)
本文为追加文章,后期慢慢追加
Linux环境:CentOS 7
1.安装squid和常用工具
# 安装squid
yum -y install sqiud
# 安装openssl
yum -y install openssl
2、修改配置文件,/etc/squid/squid.conf
# 修改配置文件
vim /etc/squid/squid.conf
# 显示如下
#acl 可以控制访问代理的IP地址,如下可以访问代理的网络是内网网络。建议查看本地的IP,做出限制。
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 作者未更改,不知道用来做什么
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
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
# 下面命令表示除上边的访问允许使用代理外,其它的都不允许。http_access allow all 表示所有人都可以使用代理,不建议给别人白嫖。
http_access deny all
# 默认3128,可以改端口
# Squid normally listens to port 3128
http_port 3128
后面可以不管!!!!!
3.启动sqiud
# 初始化服务
squid -z
# 启动squid
systemctl start squid
# 重启squid
systemctl restart squid
# 关闭squid
systemctl stop squid
4.验证squid开启
netstat -ntl
# 默认3128端口
代理认证
1.安装httpd
yum install httpd
# 生成密码文件,指定文件路径,其中user是用户名
htpasswd -cd /etc/squid/passwords user
# 提示输入密码,输入密码任意
2.添加用户
# 第一个目录是用户存储的文件,一般是下面的文件,或者包括ncsa_auth名的文件;
# 第二个文件时密码所在的文件,是上面命令的文件路径。
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5 # 最多 5 个账户同时运行
auth_param basic credentialsttl 2 hours # 认证持续时间
auth_param basic realm Example.com's Squid proxy-caching
acl user proxy_auth REQUIRED # 对 user 进行外部认证
http_access allow user # user 用户要和上面的用户一致
http_access deny all # 一定要有
3.重启sqiud
# 初始化服务
squid -z
# 启动squid
systemctl start squid
# 重启squid
systemctl restart squid
# 关闭squid
systemctl stop squid
4.关闭防火墙
# 永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
# 重启防火墙
systemctl enable firewalld
service iptables restart
# 关闭端口
firewall-cmd --zone=public --add-port=80/tcp --permanent #开放80/tcp端口 (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --query-port=80/tcp #查看80/tcp端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent #关闭80/tcp端口