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!!
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.
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.
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?
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
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
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.
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 😀
@@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
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
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/
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 ?
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
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
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.
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
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
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
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
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
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!
@@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 :)
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
@@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?
@@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.
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
@@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
@@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.
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
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!
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.
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.
No beating around the bush, straight to the point, easy examples, and answering questions in the comments. You sir are amazing
This is by far the best nginx proxy tutorial I've seen in many years of doing this. It should be the standard.
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!!
Hey Brendan, no problem at all! Happy to hear that you've found this helpful!
Even now this is a bangger of a tutorial. 10/10 would recommend. You saved me multiple days of studying.
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.
Sorry i quite new to docker deployment, can i know how to make it ssl and https with 443
Can you make a tutorial on how to apple letsencypt certificates to those domains?
Simple and straight to the point, thanks a lot sir!!!!
Thank you for the nice feedback!
Instantly subscribed, what a clear ans straigth forward tutroial. Thanks man!
Thanks a lot! Appreciate that! 🙌
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.
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?
how you can add ssl certificate for those subdomains ?
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
Are the domains registered?
The nane of the file must be the same as the domain?
Thanks a lot!
Why not run the reverse proxy on a container too?
That is a good point! Thanks!
Did you edit the default file any? Also subscribed, great video!
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
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
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.
Hi ,can you post cluster management on Docker container like 1 load balancing 2 reachable 3 not reachable ,how do health check
That is a good idea! I will put it in my todo list and might give it a try!
Did you also create A records for these domains?
Hi Shanah,
Yes I had the DNS records all pre-configured.
@@bobbyiliev_ Thank you very much!
@@shanahjrsuping7344 No problem at all! Happy to help.
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 😀
Hi, yes that is a good point! You could try using Docker Compose, or an automation tool like Ansible to automate the manual tasks.
Bobby Iliev how can i integrate it into a pipeline like Jenkins or gitlab ci ?
@@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
Tks, Bobby! :)
I don't have domain name configured for my server. I am trying to achieve the same using public ip. Is that not possible?
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
Hello,
If you run docker network inspect do you see all services inside that network?
Hi, nginx its instaled on your "server" ? or its like an other container?, thanks for the tuto
I need the docker to point a domain I have, How to go for that ?
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/
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 ?
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
Best tutotrial
Thank you!
how did you enable the sub-domian feature can we configure this with out name server and local machine ?
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
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.
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
You can also run nginx as a docker container right?
Yes
Yes absolutely. It might be even better in some cases.
This video sir is just perfect, thank you
thank you so much for the video, hope this is not a stupid question , is this information in the video valid in 2024 ?
this is really helpful. thanks for sharing.
Glad it was helpful!
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
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
@@bobbyiliev_ cool will do.. thanks for your help
Thank you so much, I have learned a lot from you.
🙌🏽🙌🏽🙌🏽
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?
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
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
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!
@@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 :)
@@Ashish447 Sounds like a plan! Let me know how it goes!
@@bobbyiliev_ sure!
The big problem is that you have to manage the ports, and it will be difficult with multiple projects having their own team.
Why this way working only with Ubuntu ? I tried also with red hat / centOS, arch , open suse but no results .
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
@@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?
@@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.
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
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
@@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
@@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.
@@bobbyiliev_ Same error brother after moving to /etc/ssl/
@@aravinddas1720 What is the error that you get when running an Nginx config test with this command:
sudo nginx -t
Thank you so much!! Excellent Example!
Thank you! Happy to hear that it was helpful!
Perfect
Thanks!
Thanks for the video, really helped
Glad to hear it!
Thanks ! It's very helpful
Great video, thanks
No problem at all! Happy to hear that it was helpful!
Thank you my friend!
No problem at all! Happy to hear that this was helpful!
perfect tutorial !
Nice
Thank you!
'-dit' option mean what? it's wired!
-d = Detached
-i = Keep STDIN open even if not attached
-t = Allocate a pseudo-tty
Zdravei moje li da me posuvetva6 kak moga pusna wordpress multisite on docker localhost .
Привет, тук има добър пример за това:
github.com/pie-inc/docker-wordpress-multisite
what about the https ?
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
Me has cambiado la vida y mi hosting poniéndome limites por crear subdominios xD
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!
nice
Thanks!
Nice 👍
No problem at all! Happy to hear that it helped! 🙌
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.
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.
Nice! tansks!
No problem! Thank you for the feedback!
🙌🏽
🙌🏽🙌🏽
It's an httpd appache revers server not an Nginx one.
Not really, it is an Nginx Reverse proxy, in this case the Apache httpd was just the backend service, but it could be anything
👍
🙌
0:44
6:58
🙌