user706838
user706838

Reputation: 5380

How to configure NGINX routes?

I have 5 lamp containers (tutum/lamp) with mounted ports as follows:

127.0.0.1:81:80
127.0.0.1:82:80
127.0.0.1:83:80
127.0.0.1:84:80
127.0.0.1:85:80

What I would like to do is put an NGINX in front of them so that it redirects to the appropriate containers depending on the URL. For example, let's assume that the host IP is 12.45.5.113. Then, when I visit 12.45.5.113/c1/ I want to get redirected to home page of container 127.0.0.1:81:80, when I visit 12.45.5.113/c2/ I want to get redirected to home page of container 127.0.0.1:82:80 and so on so forth.

How should the NGINX configuration look like? Should I installed NGINX on the host with apt-get install or it could be possible to install it as a additional container too?

Upvotes: 1

Views: 232

Answers (1)

Mateusz Moneta
Mateusz Moneta

Reputation: 1640

I think easiest approach is to launch nginx in container.

docker run --port 80:80 --link c1 ... --link cn ... nginx

with config like (can be mounted from host by --volume argument to docker run):

{
   listen 80;
   location /c1/ {
      proxy_pass http://c1;
   }

   ...
   location /cn/ {
      proxy_pass http://cn;
   }
}

this way it will redirect all request as you wish using Docker container linking mechanism (all request will be routed through bridge network).

For more information check Docker documentation: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#/connect-with-the-linking-system

Upvotes: 1

Related Questions