Answer the question
In order to leave comments, you need to log in
How to run multiple sites on the same host, so that each has its own set of Docker containers and that they are accessible on the same port 80?
There are several sites, each running in the Nginx + PHP + MySql / Postgre stack, which runs in containers via `docker-compose`. That is, each has its own set of containers and they all run on the same server. Everyone has their own Nginx and they listen to different ports: from 81 to 90.
Most have their own domain. All domains point to the same IP of this server.
In a separate container, 1 more Nginx is launched, which, depending on the domain in the request, passes the request to the rest of Nginx:
server {
server_name etova.ru;
location / {
proxy_pass http://localhost:81/;
}
}
server {
server_name site.ru;
location / {
proxy_pass http://localhost:82/;
}
}
Answer the question
In order to leave comments, you need to log in
There is a ready-made solution: nginx-proxy/nginx-proxy
Automatically restarts and generates a config for running containers.
Projects should stick out ports in one general network. It is possible in several: project network + network for ports outside.
Use traefik as a balancer. Nginx of each application does not need to shine outside. Only traefik looks at the ore. What and where to proxy is described in the labels of the service in docker-compose
In my opinion, it would be more correct to run one nginx for all sites. Otherwise, if there are several of them, they may conflict. I implemented it this way, that is, each site has its own config file in /etc/nginx/sites-enabled.
and they are all listening on port 80.
server {
listen 80;
listen [::]:80;
server_name etova.ru;
location / {
proxy_pass http://localhost:8080;
}
}
server {
listen 80;
listen [::]:80;
server_name site.ru;
location / {
proxy_pass http://localhost:8081;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question