Home > other >  Nginx - with the same domain from multiple Docker container on port 80
Nginx - with the same domain from multiple Docker container on port 80

Time:11-20

My question is similar to this problem, but only one domain.
Whether can run multiple docker containers on the same server, all of these containers on port 80, but with a different URL path?
For example:
Internally, all applications hosted on the same docker server.

172.17.0.1:8080=& gt; App1
172.17.0.2:8080=& gt; App2
172.17.0.3:8080=& gt; App3

In the external, the user will use the following URL to access the application:

www.mydomain.com (app1)
www.mydomain.com/app/app2 (app2)
www.mydomain.com/app/app3 (app3)

CodePudding user response:

I use nginx reverse proxy to solve the problem.
This is nginx container Dockerfile:

The FROM nginx
COPY nginx. Conf/etc/nginx/nginx. Conf

This is nginx. Conf:

HTTP {

Server {
listen 80;

The location/{
Proxy_pass http://app1:5001/;
}

The location/API/{
Proxy_pass http://app2:5000/api/;
}
}
}

Then I stood up in the same docker network nginx, app1 and app2 container.
Make sure the location and the agent contained in the following path/, otherwise, nginx returns 502: 'Bad Gateway.'
All requests through port 80 docker host, and then handed them to nginx container, then nginx containers according to the url path to forward them to the app.

CodePudding user response:

The original poster to solve, I also encountered this problem
  • Related