How do I setup NGINX configuration to reverse proxy to multiple containers using different proxies and site files -


i working on setting our development environment using vagrant, docker , nginx (among other tools).

we have common microservice architecture , using container per microservice.

as proof of concept, using 2 test microservices try work out development environment, a , b.

we running 3 containers (nginx,a,b) purpose of proof of concept.

using reverse proxies in nginx, want able use following proxies.

http://localhost:8181/a/ proxies request ip address of container 'a' http://localhost:8181/b/ proxies request ip address of container 'b'

to this, want defer management of each of services nginx configuration service itself. hopefully, allow each of service add/remove/modify entries /etc/nginx/sites-available volume shared containers , host os.

for example, think need following structure in nginx

/etc/nginx    - nginx.conf    - sites-available      -      - b    - sites-enabled      - (sym link sites-available/a)      - b (sym link sites-available/b) 

the nginx.conf file looks following:

worker_processes  4; events {     worker_connections  1024; }  http {     include /etc/nginx/conf.d/*.conf;     include /etc/nginx/sites-enabled/*; } 

assuming when pull ip addresses of containers a , b following

a -> 172.17.0.1

b -> 172.17.0.2

and have container a exposing port 1234 , container b exposing port 5678, should a , b files under sites-available?

i tried following , similar variations, can't seem use both /a , /b proxies.

excerpt /etc/nginx/sites-available/a

server {     listen 80;     location /a/ {             proxy_pass http://172.17.0.1:1234/;     } } 

excerpt /etc/nginx/sites-available/b

server {     listen 80;     location /b/ {             proxy_pass http://172.17.0.2:5678/;     } } 

for example, using configuration following results

http://localhost:8181/a/ proxies container 'a' fine

http://localhost:8181/b/ gives connection refused


Comments