F
F
FLASH9112020-01-27 13:07:34
Nginx
FLASH911, 2020-01-27 13:07:34

How to setup NGNIX+Docker-compose with subdomains?

You need to configure nginx to work with subdomains so that each subdomain sends to its own container. Now for tests I use the old domain, which is configured (records) for my ip. NGINX is installed in a separate compose container, the settings are as follows:

nginx.conf:

server {
      listen          80;
      server_name     phpmyadmin.example.com www.phpmyadmin.example.com;
      location / {
         resolver 127.0.0.11;
     set $project http://phpmyadmin:80;
    
     proxy_pass $project;
      }
  }
  server {
      listen          80;
      server_name     bob.example.com www.bob.example.com;
      location / {
    resolver 127.0.0.11;
    set $project http://bob:80;
    
    proxy_pass $project;      
    }
  }


docker-compose.yml

version: '3.7'

services:
  nginx:
    container_name: nginx
    build: .
    networks:
      nginx_net:
    volumes:
      - ./data/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 80:80

networks:
  nginx_net:
    name: nginx_net


However, an error is thrown for subdomains and containers are not available, but for example.com it gives a 502 error. How to properly configure nginx to work with subdomains?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2020-01-28
@opium

Use traefik or any analogue, Guinness is not needed here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question