簡體   English   中英

NGINX 容器作為其他 docker 容器的代理

[英]NGINX container as a proxy for other docker containers

我有 bind9 DNS 服務器作為容器運行,並映射到 docker 主機上的端口 53003:

version: "3"
services:
  DNS-SRV:
    container_name: DNS-SRV
    image: ubuntu/bind9
    ports:
      - "53003:53"
    environment:
      - TZ=UTC
    volumes:
      - ~/core/bind9/:/etc/bind/

我想知道我是否可以使用 NGINX 服務器作為它和其他容器化服務的代理,這是我的 nginx.config 文件:

events {
  worker_connections 1024;
}

stream {

    upstream dns_servers {
        server <docker_hostIP>:53003;
    }

    server {
        listen 53 udp;
        listen 53; #tcp
        proxy_pass dns_servers;
        error_log  /var/log/nginx/dns.log info;
        proxy_responses 1;
        proxy_timeout   1s;
    }
}

我想要做的是 map 任何 dns 請求 docker 主機在端口 53 到端口 53003,我不確定是否有另一種方式:

客戶端 -- DNS 請求 ---> 53 (( [ NGINX ] --> 53003:53 ))

我的設置不起作用,我正在通過這樣的 nslookup 進行測試:

# nslookup <domain> <docker_hostIP>

但是我的連接超時,可能是什么問題?

你能做到這一點嗎? 創建包含這兩項服務的 docker-compose

version: "3"
services:
  DNS-SRV:
    container_name: DNS-SRV
    image: ubuntu/bind9
    environment:
      - TZ=UTC
    volumes:
      - ~/core/bind9/:/etc/bind/
  NGINX:
    image: nginx:alpine
    ports:
      - "53:53/udp"
      - "53:53/tcp"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - "DNS-SRV"

然后在你的 nginx.conf 做這樣的事情?

events {
  worker_connections 1024;
}

stream {

    upstream dns_servers {
        server DNS-SRV:53;
    }

    server {
        listen 53 udp;
        listen 53; #tcp
        proxy_pass dns_servers;
        error_log  /var/log/nginx/dns.log info;
        proxy_responses 1;
        proxy_timeout   1s;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM