Squid代理配置

某些平台的服务需要配置白名单IP或服务器,我们配置了某个服务器,但是其他服务器也想访问这个平台,可以在白名单服务器上安装Squid,将其他服务器的服务代理到目标平台。

一、安装配置squid

图片

首先在白名单服务器上安装squid:

1.切换到root用户下,运行 apt update 命令进行升级,之后运行 apt install squid 安装 squid

2.安装完毕后会生成 /etc/squid/ 目录,运行 systemctl status squid 可以查看 squid 状态,正常则表明安装成功

配置squid:

1.进入 /etc/squid/ 文件夹,默认有 errorpage.css 和 squid.conf 两个文件,编辑 squid.conf 文件,将内容修改如下:

## acl

acl allowed_ips src "/etc/squid/allowed_ips.txt"



## white list ips

http_access allow allowed_ips



## apply acl

# Only allow cachemgr access from localhost

http_access allow localhost manager

http_access deny manager

# from where browsing should be allowed

http_access allow localhost

# And finally deny all other access to this proxy

http_access deny all



# app settings

http_port 8888



# cache settings

cache deny all



## log settings

logformat squid_json {"@timestamp":"%ts%03tu","client_ip":"%>a","response_time_ms":%tr,"squid_status":"%Ss","http_status_code":"%03>Hs","send_size":%>st,"receive_size":%<st,"request_method":"%rm","request_url":"%ru","domain":"%>rd","scheme":"%>rs","request_port":"%>rP","dest_ip":"%<a","mimetype":"%mt"}

logformat squid      %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %[un %Sh/%<a %mt

access_log   /var/log/squid/access_json.log squid_json

access_log   /var/log/squid/access.log squid

logfile_rotate 30



## proxy settings

forwarded_for off

 2. 仍然在 /etc/squid/ 文件夹下,创建 allowed_ips.txt 文件,将允许使用交易key的服务器ip写入到此文件,allowed_ips.txt内容示例如下(根据实际情况修改):


10.10.3.97
10.10.3.98

3.完成以上步骤后,需运行 systemctl restart squid 命令重启squid,重启完成后 ip为 10.10.3.97 和 ip 为 10.10.3.98的服务器就可以通过本服务器代理访问目标平台了。

二、配置示例

以某个Python工程为例,找到配置文件,增加白名单服务器(假设为:10.10.3.96)的配置,配置示例如下:

taskx:

      proxy_host: 10.118.0.244  #白名单ip

      proxy_port: 8888          #空闲端口

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值