xiao
xiao
发布于 2023-06-21 / 124 阅读 / 0 评论 / 0 点赞

squid正向代理

内外网环境,做了网络隔离,只有一台机器能够访问外网。 故在该机器上配置代理服务器,进行代理转发。 之前使用Nginx,但是发现nginx支持不了https的请求 (强行支持也行,需要装一些额外包,源码编译,没必要折腾)

这里记录下一个Squid的快速配置安装

安装

可以采用多种方式安装。装好后,一般在/usr/sbin/squid 默认配置文件是:/etc/squid/squid.conf

yum install squid

修改配置文件

如果没有root权限,建议就在自己的目录建一个squid.conf copy一个下面的demo。 (这个是从默认的/etc/squid/squid.conf里面复制出来的。)

一般情况下只需要修改下, 服务端口 http_port: 10000 日志文件路径之类的。

如果没有root权限,记得把里面的log路径,pid路径修改下。

#
# Recommended minimum configuration:
#

# Squid normally listens to port 3128
http_port 10000  

# 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 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
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all



# 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
cache_mem 32 MB
cache_dir aufs /home/wxadmin/app/squid/cache/ 1024 16 256
access_log /home/wxadmin/app/squid/log/access.log
cache_log  /home/wxadmin/app/squid/log/cache.log
pid_filename /home/wxadmin/app/squid/squid.pid

#
# 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

初始化/启动/停止

squid需要进行初始化才能使用。 -f 参数指定自定义配置文件。 一些常用命令。

#初始化
/usr/sbin/squid -f /home/wxadmin/app/squid/squid.conf -z
# 开始
/usr/sbin/squid -f /home/wxadmin/app/squid/squid.conf start
# 重启
/usr/sbin/squid -f /home/wxadmin/app/squid/squid.conf restart
# 关闭
/usr/sbin/squid -f /home/wxadmin/app/squid/squid.conf -k shutdown

检查

检查端口,是否10000端口在服务。

netstat -lnp

检查是否配置成功

curl -x 127.0.0.1:10000 https://www.baidu.com