nginx作为具有地图的docker上游代理

时间:2015-07-14 16:55:28

标签: nginx proxy docker

尝试使用docker在代理服务器后面使用nginx maps选项设置一堆应用程序,以便于使用大量后端应用程序进行配置。

我遇到的麻烦是容器无法通过链接解析我给它的地址。

我尝试过使用dnsmasq,但这很麻烦,并没有给我一个有效的解决方案。

有什么建议吗? nginx.conf:

events {
    worker_connections  1024;
}

http {
  map $hostname $destination {
    hostnames;
      default host1:81;
      host1.test.local host1:81;
      host2.test.local host2:82;
      host3.test.local host3:83;
   }
   server {
     location / {
       proxy_pass http://$destination/;
     }
   }
}

搬运工-compose.yml:

webproxy:
  build: nginx:latest
  ports:
    - "80:80"
  volumes:
    - nginx.conf:/etc/nginx/nginx.conf
  links:
    - "host1:host1"
    - "host2:host2"
    - "host3:host3"

host1:
  image: nginx:latest
  ports:
    - "81:80"
  volumes:
    - host1/index.html:/usr/share/nginx/html/index.html

host2:
  image: nginx:latest
  ports:
    - "82:80"
  volumes:
    - host2/index.html:/usr/share/nginx/html/index.html

host3:
  image: nginx:latest
  ports:
    - "83:80"
  volumes:
    - host3/index.html:/usr/share/nginx/html/index.html

我经常遇到错误:

webproxy_1 | 2015/07/14 16:44:11 [error] 5#0: *1 no resolver defined to resolve host1, client: 10.0.2.2, server: , request: "GET / HTTP/1.1", host: "host2.test.local:8281"
webproxy_1 | 10.0.2.2 - - [14/Jul/2015:16:44:11 +0000] "GET / HTTP/1.1" 502 181 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0"

0 个答案:

没有答案