Docker

Squid 代理服務配置問題

  • June 28, 2021

我已經安裝了 squid 代理來過濾來自 docker 的出站流量。具體來說,我使用 docker 創建了一個 jupyterhub 環境,以隔離每個使用者並為他們提供虛擬環境。

現在我想過濾出站流量,以便他們只能訪問某些域和使用 jupyterhub 的 docker 在本地安裝的服務。

使用 cURL 呼叫代理可以正常工作。它只允許輸入的域並使我們訪問本地的 jupyterhub 服務。但是,要從Web界面打開它,會發生此錯誤:

在此處輸入圖像描述

我已經啟用了 ip 172.17.0.1 和埠 8081 的服務,並且 cUrl 測試正在執行。

我該如何解決?

一些配置:

config.json (~/.config.json):

{
"proxies":
{
  "default":
  {
    "httpProxy": "http://127.0.0.1:3128",
    "httpsProxy": "http://127.0.0.1:3128",
    "noProxy": "127.0.0.0/8"
  }
}
}

squid.conf (/etc/squid/squid.conf):

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 localnet src 172.17.0.1/32

acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 443         # https
acl CONNECT method CONNECT

#### 23/06/2021 #############
acl jupyterhub_port port 8081
acl jupyterhub_addr dst 172.17.0.1
http_access allow jupyterhub_port jupyterhub_addr

# 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

###### 18/06/2021

acl whitelist dstdomain .python.org .pypi.org .pythonhosted.org .pypa.io .yahoo.com
http_access allow whitelist

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

# Squid normally listens to port 3128
http_port 3128

# 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

通過代理捲曲:

curl http://172.17.0.1:8081/hub/api --proxy 127.0.0.1:3128
{"version": "1.4.1"}

最後,我的配置文件是正確的;)我只是在 config.json (~/.config.json) localhost 中指定了錯誤,而不是 ip LAN 地址(docker 是外部環境):

{
"proxies":
{
  "default":
  {
    "httpProxy": "http://172.31.31.111:3128",
    "httpsProxy": "http://172.31.31.111:3128",
    "noProxy": "172.31.33.81/8"
  }
}
}

引用自:https://serverfault.com/questions/1067574