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.
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"
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.
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.
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
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.
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 ?
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)
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.
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?
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 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 ?
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?
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.
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?
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.
@@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
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.
If you enjoyed this, check out my Introduction to NGINX on udemy
grab a discount coupon here
www.husseinnasser.com/courses
I just got it, and enjoying it so far
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.
My proxy server does not run and it gives in 502 error. Followed the same step by step as shown in the video
anybody else get a 502 bad gateway error when trying to load their local host page? or do anyone know what piece im missing ?
"I'm going to use vim" good lad, hitting subscribe
Dean Moore vim is awesome 😎
I appreciate the great video. Thank You for putting it together
Hussein a man with energetic voice ;)
Thanks a lot, man.!!!
Greetings from Mexico
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"
This is great tutorial Hussein, Thank you for sharing... Can you do a Traefik proxy using docker that'd be great.
thanks that was great. Quick and Concise
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.
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
@@hnasr it's kinda sad that you made that video members only as it was my only reference for nginx related stuff :(
Just need to make sure one thing what did you write in the nginx.conf file
how would i make it not round robin. is there a way to do it using subdomains?
Its nice that youtube got x2 option
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.
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
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.
Shahin Bayat thanks Shahin! Ill take a look at Traefik good idea!
many thank brooo. you saved my paper !!
will this conf work for tcp ?
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 ?
Thanks for sharing. Appreciate it.
I like how eccentric you are
Great video nice simple
Thanks for sharing!!!! Great learning
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)
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.
How can i load Balance post request
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?
if i don't use http at proxy_pass what will be happened?
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?
It looks like you wrote nginx.conf but your host cannot be found.
You sure you have the host up and running?
@@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 ?
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?
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.
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?
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.
@@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
@@adambaker1777 hey Adam, can you help me? i keep facing the 502 problem
but the all three port is open 2222 and 3333. outside people can access those port.
Excelente video !
Great video!
okay okay, okay, 'subscribed'!
The tutorialwas simple mate..but when I tried it out...it was prompting an error
Thank you Hussein. Nice video.
Here is my implementation: github.com/kerolloz/loadbalancer-nginx-nodejs-example.
Well done!
Thanks to your great videos ✨
hey dude so you never assign the ports for the nodejs instances how does it maps the nodejs ports????
@@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
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.
proxy_pass ❤