How to Host Multiple Docker Containers on a Single Server with Nginx Reverse Proxy?

Поділитися
Вставка
  • Опубліковано 25 січ 2025

КОМЕНТАРІ • 134

  • @yuvvrajkperson
    @yuvvrajkperson 2 роки тому +16

    No beating around the bush, straight to the point, easy examples, and answering questions in the comments. You sir are amazing

  • @hostinggeek
    @hostinggeek 5 місяців тому +3

    This is by far the best nginx proxy tutorial I've seen in many years of doing this. It should be the standard.

  • @brendang8610
    @brendang8610 4 роки тому +17

    I have been stuck for so long trying to configure the server blocks for my docker droplet. For a beginner like me who until today hadn't even heard of a server block, this was so much more informative than the digital ocean documentation on setting up nginx!!

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +2

      Hey Brendan, no problem at all! Happy to hear that you've found this helpful!

  • @votem2105
    @votem2105 6 днів тому

    Even now this is a bangger of a tutorial. 10/10 would recommend. You saved me multiple days of studying.

  • @josephjwilk
    @josephjwilk Рік тому

    Thank you so much for this. I have struggled with this, and with some tweaks to the firewall and certbot, it's finally working! Thank you again for the straightforward and uncomplicated directions.

  • @mamirazmi
    @mamirazmi Рік тому +3

    Sorry i quite new to docker deployment, can i know how to make it ssl and https with 443

  • @shadyjeff12
    @shadyjeff12 Рік тому +2

    Can you make a tutorial on how to apple letsencypt certificates to those domains?

  • @tsivanathan
    @tsivanathan 4 роки тому +7

    Simple and straight to the point, thanks a lot sir!!!!

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      Thank you for the nice feedback!

  • @dayumnson9769
    @dayumnson9769 4 роки тому +5

    Instantly subscribed, what a clear ans straigth forward tutroial. Thanks man!

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      Thanks a lot! Appreciate that! 🙌

  • @GkmVlogs2019
    @GkmVlogs2019 Рік тому +1

    How to access container without changing end point url... for example I have an web api. I will run my web api as 2 container like instance..I want to access.

  • @PabloBecerra
    @PabloBecerra Рік тому +1

    Nice tutorial! Thank you! I was wondering if it's possible to do the same, but with php-fpm containers. Which would be the right configuration for nginx in this case?

  • @soufianeodf9125
    @soufianeodf9125 3 роки тому +4

    how you can add ssl certificate for those subdomains ?

    • @bobbyiliev_
      @bobbyiliev_  Рік тому

      You can do that with a free Let's Encrypt SSL and certbot:
      www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04

  • @jhoanmartinezsilva2609
    @jhoanmartinezsilva2609 Рік тому

    Are the domains registered?
    The nane of the file must be the same as the domain?
    Thanks a lot!

  • @adremides
    @adremides 4 роки тому +5

    Why not run the reverse proxy on a container too?

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +1

      That is a good point! Thanks!

  • @brandonb7979
    @brandonb7979 2 роки тому +2

    Did you edit the default file any? Also subscribed, great video!

    • @bobbyiliev_
      @bobbyiliev_  Рік тому +1

      Thank you! No, I just used the default Nginx config, but I had my subdomains pre configured to point to my server before the video

  • @lifetillhope5733
    @lifetillhope5733 2 роки тому

    what about if i use nginx server as a container. mean my app deploy on one container and i have second container called nginx how i configure my nginx container as a reverse proxy? hope you understand my question. kindly reply

  • @juliokavege9772
    @juliokavege9772 Рік тому

    Nice video that help me so much. But it seen the reverse proxy i configure doesn't work. It doesn't work unless i type the port of my app. My context is : I dockerize a laravel app with 3 services(app, db , webserver(which is nginx)) and it host on hostinger vps.

  • @தியான்
    @தியான் 4 роки тому +2

    Hi ,can you post cluster management on Docker container like 1 load balancing 2 reachable 3 not reachable ,how do health check

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      That is a good idea! I will put it in my todo list and might give it a try!

  • @shanahjrsuping7344
    @shanahjrsuping7344 4 роки тому +2

    Did you also create A records for these domains?

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +5

      Hi Shanah,
      Yes I had the DNS records all pre-configured.

    • @shanahjrsuping7344
      @shanahjrsuping7344 4 роки тому +1

      @@bobbyiliev_ Thank you very much!

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      @@shanahjrsuping7344 No problem at all! Happy to help.

  • @jimmyj.6792
    @jimmyj.6792 4 роки тому +2

    Hi thanks for video but how to automate the creation of subdomain when creating a new docker image with port ? It’s a little bit sad to create manually this file for each feature that i want to deploy.
    Thanks for your answer 😀

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +2

      Hi, yes that is a good point! You could try using Docker Compose, or an automation tool like Ansible to automate the manual tasks.

    • @jimmyj.6792
      @jimmyj.6792 4 роки тому

      Bobby Iliev how can i integrate it into a pipeline like Jenkins or gitlab ci ?

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +1

      @@jimmyj.6792 I would recommend going through this tutorial here:
      www.digitalocean.com/community/tutorials/how-to-set-up-continuous-integration-pipelines-in-jenkins-on-ubuntu-16-04

  • @MarlonSena
    @MarlonSena Рік тому +1

    Tks, Bobby! :)

  • @AnanyaDasgupta-t5k
    @AnanyaDasgupta-t5k 5 місяців тому

    I don't have domain name configured for my server. I am trying to achieve the same using public ip. Is that not possible?

  • @vinodhreddy6227
    @vinodhreddy6227 4 роки тому +1

    I have a issue... I have three Ubuntu servers and I have 12 microservices. One server I created 4 services. One server one compose I configured four services.. I run I'm able register eureka all servixes... Zull gateway I can able to access fst servers but remaining I'm not able to access based on serviceId... Can I tell me where I done mistake

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      Hello,
      If you run docker network inspect do you see all services inside that network?

  • @FrankoMtz
    @FrankoMtz Рік тому

    Hi, nginx its instaled on your "server" ? or its like an other container?, thanks for the tuto

  • @adithyakannan23
    @adithyakannan23 3 роки тому +1

    I need the docker to point a domain I have, How to go for that ?

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому +1

      Hi there, I setup A records for each subdomain name to point to the Droplet's IP address before the video. Here is how you could do that:
      www.digitalocean.com/docs/networking/dns/how-to/manage-records/

  • @aloktechie7981
    @aloktechie7981 2 роки тому

    Thank you so much for the video. I have my intel NUC setup and i have domain name as well, do we need to also do port forwarding in router or Nginx will take care of it ?

  • @bobbyiliev_
    @bobbyiliev_  4 місяці тому +1

    In case that you are just getting started with Docker, I could suggest this free eBook here too:
    devdojo.com/bobbyiliev/free-introduction-to-docker-ebook

  • @zeerar
    @zeerar 2 роки тому +3

    Best tutotrial

  • @aswanthbabu1202
    @aswanthbabu1202 2 роки тому

    how did you enable the sub-domian feature can we configure this with out name server and local machine ?

    • @bobbyiliev_
      @bobbyiliev_  Рік тому

      Hey! For the example I created the DNS records in my DNS zone beforehand, but you could use your hosts file on your local machine if it is just for testing too

  • @ThisIsmeIrving
    @ThisIsmeIrving 4 роки тому +1

    does this works even if I'm using like 3 docker containers to run a single app with wordpress? I want to use nginx as a load balancer between the containers to run wordpress.

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +1

      Yep, this should work with 3 WordPress containers as well. You might have to add some extra proxy rules in the Nginx Server Blocks to make it work for WordPress

  • @pavelh2518
    @pavelh2518 4 роки тому +1

    You can also run nginx as a docker container right?

  • @santiagoale6232
    @santiagoale6232 Рік тому

    This video sir is just perfect, thank you

  •  8 місяців тому

    thank you so much for the video, hope this is not a stupid question , is this information in the video valid in 2024 ?

  • @yongquanrao7398
    @yongquanrao7398 2 роки тому +1

    this is really helpful. thanks for sharing.

  • @faisalabdi6350
    @faisalabdi6350 4 роки тому

    i tried to follow this on a Centos vm, when i browse to docker1 url, it keeps taking me to welcome centos url page for somereason, i keep having to add the port number still even though i installed nginx

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      Hi, it sounds like that the Nginx server block configuration that you have is not correct. Feel free to post a question on the DigitalOcean community forum and include your current configuration files:
      www.digitalocean.com/community/questions

    • @faisalabdi6350
      @faisalabdi6350 4 роки тому

      @@bobbyiliev_ cool will do.. thanks for your help

  • @MohammedAbdulatef
    @MohammedAbdulatef 4 роки тому +5

    Thank you so much, I have learned a lot from you.

  • @meghnamishra6659
    @meghnamishra6659 4 роки тому

    Hey if have two node Js file one for server and another for client who are communicating with same port how to create docker image for DAT?

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      Hello,
      In this case I could suggest following the steps here on how to build a Node.js application with Docker:
      www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker

  • @Ashish447
    @Ashish447 4 роки тому

    Hi, I ran into an issue while implementing this great solution. Let's say I run the Nginx server as a docker container and it remains up.
    Now I have a microservices container(dockerized), and is accessed via Nginx reverse proxy.
    In case when a microservice's container is down for sometime and then restarted, the Nginx throws an upstream error.
    The upstream error occurs even if the container is up and running.
    Would appreciate any solution for this issue

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +1

      Hi there! This sounds like an interesting setup! Indeed running the Nginx service in a Docker container sounds like a better approach in some cases.
      In your Nginx configuration, are you using the Docker container IPs for the `server_block`? It sounds like that the docker container IP changes and then the Nginx service is no longer able to connect to the upstream.
      If this is the case I could suggest 2 things:
      - Make sure to create a docker network and use the container names rather than the container IPs: www.digitalocean.com/community/questions/how-to-ping-docker-container-from-another-container-by-name
      - Make sure to specify a restart policy so that if a service crashes, it would be restarted again: www.digitalocean.com/community/questions/how-to-start-docker-containers-automatically-after-a-reboot
      Finally if none of this helps, I would recommend checking your container logs for some more information on what is wrong: docker logs container_id_here
      Hope that this helps!

    • @Ashish447
      @Ashish447 4 роки тому +1

      ​@@bobbyiliev_ Thanks for your response.
      I am referring to the containers through their container names. Digging deeper into this issue, looks like an issue not from Nginx.
      What I observed:
      I have two containers, one built on Phoenix-elixir, the other built on Flask-uWSGI.
      This upstream error doesnt occur when I tried stopping and restarting the phoenix container. The issue was specific to the flask container.
      This certainly seems to be an issue somewhere inside uWSGI. Will get back if i found a solution for this :)

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +1

      @@Ashish447 Sounds like a plan! Let me know how it goes!

    • @Ashish447
      @Ashish447 4 роки тому

      @@bobbyiliev_ sure!

  • @djcaesar9114
    @djcaesar9114 5 місяців тому

    The big problem is that you have to manage the ports, and it will be difficult with multiple projects having their own team.

  • @kalitsiadischaritos4685
    @kalitsiadischaritos4685 3 роки тому

    Why this way working only with Ubuntu ? I tried also with red hat / centOS, arch , open suse but no results .

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      Hi there,
      The approach is more or less the same, however of course there are some differences between the different Linux distros. For example to install Nginx on CetnOS you would use dnf or yum and not apt.
      You can follow the steps on how to setup Nginx server blocks on CentOS here:
      www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7

    • @kalitsiadischaritos4685
      @kalitsiadischaritos4685 3 роки тому

      @@bobbyiliev_ nope is not that the case.
      I repeat everything again, all installations done properly. Everything working fine but when it comes to serve the app, only Ubuntu is able to serve it. All other distros serve default ngnix page.
      Really strange.
      Anyway could you make one step ahead and add the ssl certificate?

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      @@kalitsiadischaritos4685 Feel free to post a question on the DigitalOcean community forum here:
      www.digitalocean.com/community/questions
      Make sure to provide as much information as possible including the Nginx server block configuration that you are using.

  • @aravinddas1720
    @aravinddas1720 3 роки тому

    Is this method same in the centos environment, if so I'm not getting the URL part could you share the docs I can refer to

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому +1

      The Nginx configuration should be the same, but the installation process and the location of the config directory is different.
      You can follow the steps on how to install Nginx on CentOS 7 here:
      www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

    • @aravinddas1720
      @aravinddas1720 3 роки тому

      @@bobbyiliev_ Bro, I thank you for writing me back, just cleared all the configuration, wanted to overcome an issue could you look into it
      error message:-
      nginx: [emerg] PEM_read_bio_X509_AUX("/root/ssl/rnddev.csr") failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)
      nginx: configuration file /etc/nginx/nginx.conf test failed

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому +1

      @@aravinddas1720 it looks like that you've added an SSL certificate to the `/root/ssl` folder, I would recommend moving it to /etc/ssl/ instead and then updating the path in your configuration accordingly.

    • @aravinddas1720
      @aravinddas1720 3 роки тому

      @@bobbyiliev_ Same error brother after moving to /etc/ssl/

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      @@aravinddas1720 What is the error that you get when running an Nginx config test with this command:
      sudo nginx -t

  • @jonnetg
    @jonnetg 2 роки тому +1

    Thank you so much!! Excellent Example!

    • @bobbyiliev_
      @bobbyiliev_  Рік тому

      Thank you! Happy to hear that it was helpful!

  • @FASHIONmanTV1
    @FASHIONmanTV1 2 роки тому +1

    Perfect

  • @soufianeodf9125
    @soufianeodf9125 3 роки тому +1

    Thanks for the video, really helped

  • @natural8471
    @natural8471 9 місяців тому

    Thanks ! It's very helpful

  • @Ombibulous_Bluegrass
    @Ombibulous_Bluegrass 3 роки тому +1

    Great video, thanks

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      No problem at all! Happy to hear that it was helpful!

  • @vietnguyen6228
    @vietnguyen6228 3 роки тому +1

    Thank you my friend!

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      No problem at all! Happy to hear that this was helpful!

  • @salarkamjoo3669
    @salarkamjoo3669 Рік тому

    perfect tutorial !

  • @hanss2006
    @hanss2006 2 роки тому +1

    Nice

  • @jiazq
    @jiazq 3 роки тому +1

    '-dit' option mean what? it's wired!

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому +2

      -d = Detached
      -i = Keep STDIN open even if not attached
      -t = Allocate a pseudo-tty

  • @georgez8506
    @georgez8506 4 роки тому

    Zdravei moje li da me posuvetva6 kak moga pusna wordpress multisite on docker localhost .

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому

      Привет, тук има добър пример за това:
      github.com/pie-inc/docker-wordpress-multisite

  • @pdamiano
    @pdamiano 4 роки тому +1

    what about the https ?

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому +2

      Hi Damiano, you can add SSL with certbot as described here:
      www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04

  • @CarlosWolfram
    @CarlosWolfram 4 роки тому

    Me has cambiado la vida y mi hosting poniéndome limites por crear subdominios xD

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      Hi there, there are a few things you could do in this case:
      * either use actual domain names for each Nginx server block
      * access the containers directly on the port
      * use 1 server block with multiple locations, for example, /app1 /app2 and etc
      Hope that this helps!

  • @zeerar
    @zeerar 2 роки тому +1

    nice

  • @தியான்
    @தியான் 4 роки тому +1

    Nice 👍

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      No problem at all! Happy to hear that it helped! 🙌

  • @ugurserhattoy
    @ugurserhattoy 3 роки тому

    Why do you need apache?
    So isn't nginx enough to do that?
    Apache + nginx might be sacrificing nginx efficiency... Sounds like running linux on a windows machine.

    • @bobbyiliev_
      @bobbyiliev_  3 роки тому +1

      The Apache containers were used only for the demo. You of course have to change them with your own application like NodeJS or whatever you are running Inside the container.

  • @Halissonskalee
    @Halissonskalee 4 роки тому +1

    Nice! tansks!

    • @bobbyiliev_
      @bobbyiliev_  4 роки тому

      No problem! Thank you for the feedback!

  • @sprintwithcarlos
    @sprintwithcarlos 4 роки тому +1

    🙌🏽

  • @HafeedElbekkaoui
    @HafeedElbekkaoui 2 роки тому

    It's an httpd appache revers server not an Nginx one.

    • @bobbyiliev_
      @bobbyiliev_  Рік тому

      Not really, it is an Nginx Reverse proxy, in this case the Apache httpd was just the backend service, but it could be anything

  • @ibrahimoglu
    @ibrahimoglu 3 роки тому +1

    👍

  • @vetorial_data_custom
    @vetorial_data_custom 3 роки тому

    0:44
    6:58