docker - Configure Nginx for routing -


i using nginx docker image on port 80 in vm (address x.y.z.w). when try http://x.y.z.w in browser, showing me nginx index file.

now configuring (basically proxy passing) 2 docker images running on same vm on ports 8081 , 8082. want:

when type http://x.y.z.w/a should go http://x.y.z.w:8081 when type http://x.y.z.w/b should go http://x.y.z.w:8082 

for this, changed portion in conf file:

     location /a {         rewrite ^/a(.*) /$1 break;         proxy_pass http://x.y.z.w:8081 ;     }      location /b {         rewrite ^/b(.*) /$1 break;         proxy_pass http://x.y.z.w:8082 ;     } 

it working expected. images in same machine (have same ip), want use localhost instead of x.y.z.w. not working localhost.

basically, don't want use hardcoded ip (x.y.z.w) in links, ip can change in future.

is there way, nginx can know variable ip on running , may use ip. or how can work localhost modification?

you can't use localhost address docker container, since refers loopback of container , not of host. @tuan suggested, can link (https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/) containers, can communicate via names. e.g.:

docker run --rm -ti --name backend nginx:latest docker run --rm -ti --name proxy --link backend:backend nginx:latest 

now proxy knows backend.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -