Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The concept of Nginx reverse proxy and load balancing and how to use upstream Module

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "Nginx reverse proxy and Load Balancer concept and upstream module how to use," interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "Nginx reverse proxy and Load Balancer concept and how to use upstream module"!

Nginx Load Balancer Concept

To be precise, Nginx is used as an Nginx Proxy reverse proxy, because this reverse proxy function shows the effect of Load Balancer, so it is called Nginx Load Balancer.

The effectiveness of implementing Load Balancer depends primarily on two components:

ngx_http_proxy_module

ngx_http_upstream_module

The former is a proxy module used to pass requests to server nodes or upstream server pools.

The latter is the Load Balancer module, which can implement the Load Balancer function of the website and the health check of the node

upstream module

The Nginx Load Balancer function relies on the ngx_http_upstream_module, and the supported proxy methods include proxy_pass, fastcgi_pass, memcached_pass, etc.; Nginx is allowed to define one or more groups of node servers, and send website requests to predefined upstream groups using proxy methods.

How to use the upstream module

Basic configuration case

upstream www_server_pools { server 192.168.1.1; server 192.168.1.2; server 192.168.1.3;}

More complete configuration case

upstream www_server_pools { server 192.168.1.1:80 weight=1; server 192.168.1.2:80 weight=2; server 192.168.1.3:80 weight=2 max_fails=1 dail_timeout=10s;}

Domain name configuration case

upstream backend { server backend1.yyang.com weight=3; server backend2.yyang.com:8080; server unix:/tmp/backend3;}upstream module description

server 192.168.1.1:80 #can be IP or domain name

weight=1 #weight value, default is 1, the larger the number, the larger the proportion of accepted requests

max_failures =1 #Number of failed attempts to connect to backend hosts

backup #hot standby configuration

fail_timeout=10s #Time to next check

http_proxy_module module

proxy_pass directive

The matching request is thrown to the defined upstream node pool through location.

proxy_pass Cases

location / { proxy_pass http://www_server_pools;} complete case worker_processes 1;events { worker_connections 1024;}http { include mine.types; default_type app/octet-stream; sendfile on; keepalive_timeout 65; upstream www_server_pools { server 192.168.1.1:80 weight=1; server 192.168.1.2:80 weight=1; server 192.168.1.3:80 weight=1; } server { listen 80; server_name www.yyang.com; location / { proxy_pass http://www_server_pools; } }} At this point, I believe that everyone has a deeper understanding of "Nginx reverse proxy and Load Balancer concept and how to use upstream module," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report