Spin up an Nginx Docker Container as a Load Balancer

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

КОМЕНТАРІ • 56

  • @hnasr
    @hnasr  3 роки тому +3

    If you enjoyed this, check out my Introduction to NGINX on udemy
    grab a discount coupon here
    www.husseinnasser.com/courses

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

      I just got it, and enjoying it so far

  • @someguyInArista
    @someguyInArista Місяць тому

    Hey there! Just wanted to drop by and share a quick story. Yesterday, I was struggling so much with this configuration that I finally gave in and went to UA-cam-lo and behold, I found your video. At that moment, I knew it was going to be a game-changer, so I shut my laptop and went straight to bed, confident tomorrow would be handled by a certified badass.
    I've been following your UA-cam channel for a few years now and even took your Backend Fundamentals course on Udemy-absolutely brilliant, by the way.Thanks for all the amazing content, man! You're a legend.

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

    My proxy server does not run and it gives in 502 error. Followed the same step by step as shown in the video

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

    anybody else get a 502 bad gateway error when trying to load their local host page? or do anyone know what piece im missing ?

  • @doghosuedean
    @doghosuedean 4 роки тому +6

    "I'm going to use vim" good lad, hitting subscribe

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

      Dean Moore vim is awesome 😎

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

    I appreciate the great video. Thank You for putting it together

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

    Hussein a man with energetic voice ;)

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

    Thanks a lot, man.!!!
    Greetings from Mexico

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

    Great video explaning how to spin up nginx load balancer. One thing that can added is that docker is member of sudo using "sudo usermod -aG docker $USER"

  • @mayurchavhan8590
    @mayurchavhan8590 4 роки тому +4

    This is great tutorial Hussein, Thank you for sharing... Can you do a Traefik proxy using docker that'd be great.

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

    thanks that was great. Quick and Concise

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

    Well spoken. Like the video a lot. Nginx docs make it so complicated. You made this so simple. I love how you just wrote the configs from scratch and explained it. I would recommend in future videos typing out the line and then talking about it so that people can type it out while you speak. Also, have you done a video using nginx and an SSL certificate? I'll search your videos, but if you haven't that would be a great addition.

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

      Justin Roysdon thanks Justin!
      Yes this is a 2 hours video discussing nginx 2 Hours NginX Crash Course + Bonus Content (Audio Fixed)
      ua-cam.com/video/hcw-NjOh8r0/v-deo.html

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

      @@hnasr it's kinda sad that you made that video members only as it was my only reference for nginx related stuff :(

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

    Just need to make sure one thing what did you write in the nginx.conf file

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

    how would i make it not round robin. is there a way to do it using subdomains?

  • @ash-faque
    @ash-faque 2 роки тому +1

    Its nice that youtube got x2 option

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

    Hussein...Eid Mubarak. Thank you for sharing this video. I was getting 502 Bad Gateway initially when I tried to use localhost (for my node instances) inside my docker image. Replaced localhost with IP, and it working now.

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

      Joseph Khan Thank you for Eid wishes ❤️ Eid Mubark to you too if you celebrate
      Yeah using localhost in the docker can be confusing. The best thing is to use ip address or host name
      Check out this video where i show how to spin up multiple microservices in docker ua-cam.com/video/9sAg7RooEDc/v-deo.html

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

    Thanks dude. Traefik is also grabbing attentions and seems to work very well with containers, the API GUI is also interesting🙂 . I think it is also able to solve the problem of lacking load balancers in docker Swarm. Would be great if you could have an introductory video on it. Many thanks as always for your nice vids.

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

      Shahin Bayat thanks Shahin! Ill take a look at Traefik good idea!

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

    many thank brooo. you saved my paper !!

  • @KunalChander-b1j
    @KunalChander-b1j 7 місяців тому

    will this conf work for tcp ?

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

    Hello Hussein, thanks for your tutorial. is there any configuration if we config this through public cloud such as GCP or AWS ?
    do you ever config it ?

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

    Thanks for sharing. Appreciate it.

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

    I like how eccentric you are

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

    Great video nice simple

  • @nithinstrack-shiningsun5556
    @nithinstrack-shiningsun5556 4 роки тому

    Thanks for sharing!!!! Great learning

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

    Are there any pros/cons to running ngnix as docker image vs running it at host natively? like whether it's good if it fails for some reason but the the server is still reachable (i know you can configure it to auto restart but it can still fail that)

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

      Excellent question, it really depends on your architecture and management.
      If you have NginX as a container spinning up a new container is always faster than spinning up a completely new HOST (VM or physical) with OS and all that bloat just to spin up NginX.
      That being said managing containers is an extremely difficult problem and an infrastructure cost that is why Kubernetes and Mesos exist.
      If you decided to host NginX yourself in VMs. Running Docker in a single host with multiple containers is still prune to a single point of failures. if the host fails all your containers are dead. So naturally, you will need another backup host with backup containers and you start which increases your infrastructure cost.
      It might be easier just to run NginX natively on your host but if you are running multiple services and stuff on the same HOST nginx might starve and can't serve your requests. A problem that doesn't exist in containers because of resource isolation (each container gets a cut of RAM/CPU)
      So yes in summary Pros & cons of everything, containers are lightweight, faster to spin up, isolated but costly to maintain and require multiple hosts (pods) anyway and definitely require a container orchestrator like K8 to manage the mess and most probably you will start needing a service mesh which will just double your infrastructure costs.
      Alternatively, you can have some VMs and run NginX natively on them, but you will eat the cost of slow scaling .. I hear microVMs is a think now that gives you isolation. If you have few clients probably not a bad idea to start this way and avoid the complexity of microservices.

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

    How can i load Balance post request

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

    I use to deploy web applications on Digital Ocean VPC. Normally, I had one LB which is one server. And 2 applications that are on separate on different servers. So, a total of 3 servers.
    Can you please explain how it gonna archive with docker?

  • @mr.chowdhury2737
    @mr.chowdhury2737 3 роки тому

    if i don't use http at proxy_pass what will be happened?

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

    Hi Hossein It was a great video I have an issue : when I run the docker its write : host not found in upstream "najeebs-virtual:2222" in etc/nginx/nginx conf:3
    when I run the server browser it's write the nginx server is working ....
    I think that the nginx.conf didn't replace as you said ...
    what do you think?

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

      It looks like you wrote nginx.conf but your host cannot be found.
      You sure you have the host up and running?

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

      @@hnasr Umm sorry I'm really jonior in linux, now I found out that I didn't make any host in my VM , so I tryed to write localhost:2222 and localhost:3333
      And it runed the docker , the problem is that in the google browser write what it is written in the index.html in usr/shared/nginx/nginx.html ...
      Witch is my hostname vm it should be that or something else?
      And if it is true could I create more than one host name in my VM ?

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

    Wouldn't you have, in the end, localhost:2222, localhost:3333 and localhost:8080 running? Is it possible for port 2222 and 3333 not be accessible meanwhile port 8080 be running?

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

      Good question! Yes it is possible in this case the proxy is available but none of backends are. In this case the proxy will reply with 5xx error usually service unavailable error.

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

    Hey Hussein, great video. Like some others in the comments, I am experiencing a 502 bad gateway error. I attempted to map to my private IP in the upstream of the nginx.conf file, but the 502 error persisted. I can get a response in the browser from my upstream servers using the same IP, but I cannot get them to be served by the load balancer. For context I am running on Docker Desktop for Windows, I don't know if that matters. Any thoughts here?

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

      Bad gateway means that you can reach the load balancer but the load balancer can't reach the backend for some reason. Try bashing into the container running nginx and ping the backend ip.

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

      @@hnasr Thanks for the super quick reply, I really appreciate it. You were right, I could not ping my local IP from inside my docker container. After figuring this out it took me a while, but I found that you can route traffic to host.docker.internal inside the Nginx file and it will route to the localhost. So I am now happy to report that the load balancer is up and running. Really appreciate your content and responsiveness Hussein. Keep it up.
      Details about host.docker.internal for others experiencing the same problem -- stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach

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

      @@adambaker1777 hey Adam, can you help me? i keep facing the 502 problem

  • @mr.chowdhury2737
    @mr.chowdhury2737 3 роки тому

    but the all three port is open 2222 and 3333. outside people can access those port.

  • @LuisMorales-oc5sz
    @LuisMorales-oc5sz 4 роки тому

    Excelente video !

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

    Great video!

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

    okay okay, okay, 'subscribed'!

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

    The tutorialwas simple mate..but when I tried it out...it was prompting an error

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

    Thank you Hussein. Nice video.
    Here is my implementation: github.com/kerolloz/loadbalancer-nginx-nodejs-example.

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

      Well done!

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

      Thanks to your great videos ✨

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

      hey dude so you never assign the ports for the nodejs instances how does it maps the nodejs ports????

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

      @@kumarvadivel4328 1 year later , i guess it takes the default port 5000 ? but i don't get how to they all run on port 5000

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

    Meh! Good but without dropping one of the web servers, you're not actually showing if load balancer works or not, also it would be way better with three web servers.

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

    proxy_pass ❤