Nginx ~ Add Server Load balancer for docker containers, nginxdocker
As the most popular Server Load balancer and reverse proxy server, Nginx runs on linux. to achieve traffic distribution and load balancing, You need to deploy on IIS of multiple application servers, use some tools to synchronize code, and then configure them on nginx.
With docker, you can run it in one second on multiple linux systems without deploying it on iis. For docker, nginx deployment is more convenient!
Next, let's take a look at the standard Nginx configuration file.
We can add a conf configuration file for each website, and then include the files when nginx is loaded. You don't need to pay attention to them. Haha, let's take a look at their standard content.
Server {listen 8080; server_name localhost; location/{proxy_pass http: // api; proxy_set_header Host $ host: 8080; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;} upstream api {server 192.168.200.108: 5000 weight = 1; server 192.168.200.108: 5001 weight = 1; # high weight}
The server node mainly configures information about the website. proxy_pass is the domain name and port for external Website access. When an upstream node exists, it is the name of the node and listen is the listening port!
The upstream node is the Server Load balancer information of the website. You can set the number of sites in the cluster. Of course, the data synchronization between these websites is not required for nginx!
When an application encounters a problem, we can view the log files, access. log and error. log, as shown in the following directory:
They will record the clients when they visited our website, the websites with loads, and so on. The log information is useful for future data analysis!
Thank you for reading this article!
I hope this article will help you!