L
L
Lexxtor2020-12-31 00:38:10
Nginx
Lexxtor, 2020-12-31 00:38:10

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/;
    }
}


How normal is this?
Is it more correct to make 1 Nginx for everyone, but so that everyone has their own php-fpm?
This can be done if you write the same name for network in each docker-compose.uml ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2020-12-31
@sergiks

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.

A
Andrey Zubkov, 2020-12-31
@zubkov_work

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

A
Asad Ganiev, 2021-01-07
@asadganiev

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 question

Ask a Question

731 491 924 answers to any question