Dieses Blog durchsuchen

Freitag, 14. April 2017

Nginx + docker set up a reverseproxy with dockers nameserver

If you loadbalance 2 or more nginx containers you will need to use dockers magic dns under 127.0.0.11

Here is a sample site conf of nginx which proxies every request to  a container "nginx" via proxy_pass


on your loadbalancing container edit /etc/nginx/sites-available/<your site>

server
{
  listen 80;
  resolver 127.0.0.11;
  set $upstream http://nginx;
  location /
  {
    proxy_pass $upstream;
  }
}

the variable $upstream causes, that the proxy "pings" the nameserver to respond the first answering webfrontend and routes the request to that server

Here is the complete docker-compose.yml

version: '2'
services:
proxy:
image: sameersbn/nginx:1.10.3
hostname: proxy
ports:
- "8080:80"
volumes:
- ./nginx/sites-enabled:/etc/nginx/sites-enabled
- ./logs/proxy/nginx/:/var/log/nginx
networks:
- internal
front1:
image: sameersbn/nginx:1.10.3
hostname: front1
volumes:
#- ./nginx_front1/sites-enabled:/etc/nginx/sites-enabled
- ./logs/front1/nginx/:/var/log/nginx
- ./nginx_front1/www:/usr/share/nginx/html
networks:
- internal
networks:
internal:
driver: bridge

Download the git repo here:
https://github.com/pboethig/loadbalancing 

Keine Kommentare:

Kommentar veröffentlichen