3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Proxy環境下のDify設定

Last updated at Posted at 2025-07-26

一般には環境変数 http(s)_proxy を設定してお茶を濁している人が多いと思いますが、Dify は内部で curl を使ったり、Sandbox 内では大文字の HTTP(S)_PROXY しか参照していないなどの制約があって、設定が面倒くさいです。
おそらくこんな設定になっているのではないでしょうか。

services:
  api:
    environment:
      ## curl 用に小文字設定
      http_proxy: http://プロキシアドレス
      https_proxy: http://プロキシアドレス
      no_proxy: localhost,127.0.0.1,api,worker,db,redis,weaviate,sandbox,ssrf_proxy,nginx
      ## 
      HTTP_PROXY: http://プロキシアドレス
      HTTPS_PROXY: http://プロキシアドレス
      NO_PROXY: localhost,127.0.0.1,api,worker,db,redis,weaviate,sandbox,ssrf_proxy,nginx

  worker:  ## apiと同様の設定
    environment:
      ## curl 用に小文字設定
      http_proxy: http://プロキシアドレス
      https_proxy: http://プロキシアドレス
      no_proxy: localhost,127.0.0.1,api,worker,db,redis,weaviate,sandbox,ssrf_proxy,nginx
      ## 
      HTTP_PROXY: http://プロキシアドレス
      HTTPS_PROXY: http://プロキシアドレス
      NO_PROXY: localhost,127.0.0.1,api,worker,db,redis,weaviate,sandbox,ssrf_proxy,nginx

  sandbox:  ## apiと同様の設定
    environment:
      ## curl 用に小文字設定
      http_proxy: http://プロキシアドレス
      https_proxy: http://プロキシアドレス
      no_proxy: localhost,127.0.0.1,api,worker,db,redis,weaviate,sandbox,ssrf_proxy,nginx
      ## 
      HTTP_PROXY: http://プロキシアドレス
      HTTPS_PROXY: http://プロキシアドレス
      NO_PROXY: localhost,127.0.0.1,api,worker,db,redis,weaviate,sandbox,ssrf_proxy,nginx

squid 設定によるプロキシへのフォワーディング

Dify には ssrf_proxy サービスとして squid を使用しています。
この squid の設定を変更して、

  • 外部アドレスはプロキシ経由
  • dockerプライベートネットワーク内はそのまま

とするようにします。

docker/ssrf_proxy/squid.conf.templete

## NO_PROXY向けに内部ネットワーク宛のアクセスを許可
acl localnet_dst dst 0.0.0.1-0.255.255.255      # RFC 1122 "this" network (LAN)
acl localnet_dst dst 10.0.0.0/8         # RFC 1918 local private network (LAN)
acl localnet_dst dst 100.64.0.0/10              # RFC 6598 shared address space (CGN)
acl localnet_dst dst 169.254.0.0/16     # RFC 3927 link-local (directly plugged) machines
acl localnet_dst dst 172.16.0.0/12              # RFC 1918 local private network (LAN)
acl localnet_dst dst 192.168.0.0/16             # RFC 1918 local private network (LAN)
acl localnet_dst dst fc00::/7           # RFC 4193 local private network range
acl localnet_dst dst fe80::/10          # RFC 4291 link-local (directly plugged) machines
http_access allow localnet_dst
http_access allow localnet

## 内部ネットワーク宛は直接アクセス
always_direct allow localnet_dst
always_direct allow localhost

## 内部ネットワーク以外のアクセスをプロキシにフォワーディング
cache_peer [プロキシアドレス] parent [プロキシポート] 0 no-query no-digest no-netdb-exchange default 
cache_peer_access [プロキシアドレス] allow all
never_direct allow all

docker/docker-compose.yaml

一部プログラムが ssrf_proxy を介さずに外へ出ようとするものがあるため、ssrf_proxyを通すように以下のように設定。

services:
  api:
    environment:
      HTTP_PROXY: ${SSRF_PROXY_HTTP_URL:-http://ssrf_proxy:3128}
      HTTPS_PROXY: ${SSRF_PROXY_HTTPS_URL:-http://ssrf_proxy:3128}    
  plugin_daemon:
    environment:
      HTTP_PROXY: ${SSRF_PROXY_HTTP_URL:-http://ssrf_proxy:3128}
      HTTPS_PROXY: ${SSRF_PROXY_HTTPS_URL:-http://ssrf_proxy:3128}    

この設定で各サービスにプロキシ設定を入れなくてもプラグインインストール等ができるようになっています。


squid にはあまり明るくなかったのですが、GPTに問い合わせながら上記設定にたどり着きました。
ここ最近は ggるよりもAIに聞いたほうが早い場合が多いです。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?