viewpl
By:
viewpl

How to setup nginx server blocks with docker containers?

November 29, 2014 1.8k views

Hi,

I read following article about setup nginx virtual hosts.
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

However, I require a bit further. If I have multiple docker containers with one website hosted in each, how to do that with nginx? Is there a tutorial about how to do this?

Thanks
Rob L

1 comment
  • What I would recommend is to set up your individual containers with their services listening on different ports and then use proxy_pass to proxy connections to the correct service. Since you could not have a web service in two different docker containers both listening on port 80 (at least publicly) you can use nginx to translate server blocks to ports either on the public network or the internal one used by docker.

1 Answer

This question was answered by @ryanpq:

What I would recommend is to set up your individual containers with their services listening on different ports and then use proxy_pass to proxy connections to the correct service. Since you could not have a web service in two different docker containers both listening on port 80 (at least publicly) you can use nginx to translate server blocks to ports either on the public network or the internal one used by docker.

View the original comment

Have another answer? Share your knowledge.