Docker nginx / bad gateway : multiple app with docker-compose

sorry for the question. I’m new with docker and nginx. I need some help

So, I have a docker with the nginx proxy and 3 dockers with 3 different applications

I don’t know how to configure nginx at all to avoid bad gateway errors on my 3 applications. Can you please help me?
I can only find help for this problem on 1 application.

My docker-compose

version: '2.1'

services:
    proxy:
        container_name: proxy
        hostname: proxy
        build: .docker/nginx
        ports:
            - "80:80" #80:80
            - "443:443"
        volumes:
            - ./certs:/etc/nginx/certs
            - /var/run/docker.sock:/tmp/docker.sock:ro
        networks:
            - proxy
        restart: always

networks:
    proxy:
        external: true

My DockerFile

FROM jwilder/nginx-proxy
RUN { 
  echo 'client_max_body_size 500M;'; 
} > /etc/nginx/conf.d/my_proxy.conf

App1

version: '3'

services:
    apache:
        build: .docker/apache
        container_name: app1_apache
        environment:
            VIRTUAL_HOST: "app1.local"
        expose:
            - "80"
        volumes:
            - .docker/config/vhosts:/etc/apache2/sites-enabled
            - ../../app1:/var/www/app1.local
        depends_on:
            - php
        networks:
            - default
            - proxy

    php:
        build: .docker/php
        container_name: app1_php
        environment:
            VIRTUAL_HOST: "app1.local"
        volumes:
            - ../../app1:/var/www/app1.local
        networks:
            - default
            - proxy

networks:
    proxy:
        external: true

Same file for App2 and App3

I found this solution but I don’t understand how to implement it.
nginx docker container: 502 bad gateway response
I need to modify the nginx config.d configuration file but I don’t see how I can do that.

my default config.d file

server {
   listen       80;
   server_name  localhost;

   #charset koi8-r;
   #access_log  /var/log/nginx/log/host.access.log  main;

   location / {
       root   /usr/share/nginx/html;
       index  index.html index.htm;
   }

   #error_page  404              /404.html;

   # redirect server error pages to the static page /50x.html
   #
   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
       root   /usr/share/nginx/html;
   }

   # proxy the PHP scripts to Apache listening on 127.0.0.1:80
   #
   #location ~ .php$ {
   #    proxy_pass   http://127.0.0.1;
   #}

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   #location ~ .php$ {
   #    root           html;
   #    fastcgi_pass   127.0.0.1:9000;
   #    fastcgi_index  index.php;
   #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
   #    include        fastcgi_params;
   #}

   # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
   #
   #location ~ /.ht {
   #    deny  all;
   #}
}

So, I have to add

upstream app1{
  //insert your hosts ip here
  server 192.168.99.100:8080;
}
upstream app2{
  //insert your hosts ip here
  server 192.168.99.100:8080;
}
upstream app3{
  //insert your hosts ip here 
  server 192.168.99.100:8080;
}
  • That’s right ?
  • Do I also have to change the proxy_pass?

The nginx configuration is really obscure to me.

Thank you for your help

Source: StackOverflow