Home >Backend Development >PHP Tutorial >Use nginx to implement load balancing or interface-directed distribution for URLs
Here is only one way to perform targeted distribution of interfaces for location.
The simplest configuration has been explained clearly about interface directional distribution, and other configurations will not be explained.
For example, request two URLs:
1), www.000.com/sale
2), www.000.com/matchmaker
#user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream sale { server 192.168.1.100:8000 max_fails=2; } upstream matchmaker { server 192.168.1.200:8080 max_fails=2; } server { listen 80; server_name www.000.com; location /sale { root /www proxy_pass http://sale; } location /matchmaker { root /www proxy_pass http://matchmaker; } } }
Instructions:
When When the request http://www.000.com/sale arrives, the domain name www.000.com of the listening port 80 is matched to sale according to the location, and then the corresponding field is found based on the field proxy_pass http://sale upstream, then the request will reach the machine 192.168.1.100:8000.
It achieves load balancing based on url directed forwarding
The above introduces the use of nginx to implement load balancing or interface directional distribution for URLs, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.