当前位置: 代码网 > 服务器>网络>https > Centos服务器搭建Squid Http代理请求服务器教程

Centos服务器搭建Squid Http代理请求服务器教程

2025年12月03日 https 我要评论
安装yum install squid -yyum install httpd-tools -y生成密码文件mkdir /etc/squid3/#这里密码是 ceshi htpasswd -cd /e

安装

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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com