1

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

Skyd
  • 535
  • 1
  • 4
  • 20
  • hey @skyd, i would suggest for you to try and go with https://docs.traefik.io/ instead of NGINX, i was facing the same issue with nginx and traefik is much much easier to configure and has lets encrypt support for certificates and stuff. – Eitank Mar 16 '20 at 10:20
  • Thank you for your advice @Eitank , I will look into it too. – Skyd Mar 16 '20 at 10:26
  • i have an exmaple if you need, let me know how it went :) – Eitank Mar 16 '20 at 14:39
  • Sure, with pleasure, if you have something to help me it's will be very gracefull. Maybe if you have a git repository ? – Skyd Mar 16 '20 at 14:50
  • this is something internal but i can help with whatever you need @skyd – Eitank Mar 16 '20 at 15:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/209713/discussion-between-skyd-and-eitank). – Skyd Mar 16 '20 at 15:22
  • Another recommendation: https://hub.docker.com/r/linuxserver/letsencrypt/. Very popular container, and they've done an excellent job at making it very noobie friendly, and doing almost all of the work for you. – J. Scott Elblein Mar 16 '20 at 19:42

0 Answers0