Home > Operation and Maintenance > Linux Operation and Maintenance > Website load balancing solution

Website load balancing solution

藏色散人
Release: 2019-05-03 23:15:35
forward
4542 people have browsed it

Web load balancing (Load Balancing), simply put, is to allocate "work tasks" to our server cluster, and using appropriate allocation methods is very important for protecting the back-end web servers.

Website load balancing solution

Reverse proxy load balancing

The core work of the reverse proxy service is mainly to forward HTTP requests, playing the role of the browser and the role of backend web server relay. Because it works at the HTTP layer (application layer), which is the seventh layer of the seven-layer network structure, it is also called "seven-layer load balancing". There are many software that can be used as reverse proxy, and one of the more common ones is Nginx.

Website load balancing solution

Nginx is a very flexible reverse proxy software that can freely customize forwarding strategies, allocate the weight of server traffic, etc. In reverse proxy, a common problem is the session data stored by the web server, because the general load balancing strategy allocates requests randomly. There is no guarantee that requests from the same logged-in user will be allocated to the same web machine, which will lead to the problem that the session cannot be found.

There are two main solutions:

Configure the forwarding rules of the reverse proxy so that requests from the same user must fall on the same machine (by analyzing cookies ), complex forwarding rules will consume more CPU and increase the burden on the proxy server.

It is recommended to use an independent service to store information such as session, such as redis/memchache.

The reverse proxy service can also enable caching. If enabled, it will increase the burden on the reverse proxy and needs to be used with caution. This load balancing strategy is very simple to implement and deploy, and its performance is relatively good. However, it has the problem of "single point of failure". If it hangs, it will cause a lot of trouble. Moreover, as the number of Web servers continues to increase in the later stages, it itself may become a bottleneck of the system.

Configuration file sample:

#user nobody; worker_processes 1; #pid logs/nginx.pid; events { 
    worker_connections 1024; } http { 
    include mime.types; 
    default_type application/octet-stream; 
    sendfile on;  
    keepalive_timeout 65; 
    upstream www.hcoder.net { 
        server 192.168.1.188:80 weight=5; 
        server 192.168.1.158:80; 
    } 
    server { 
    listen 80; 
    server_name www.hcoder.net; 
    location / { 
       proxy_pass http://www.hcoder.net; 
       proxy_set_header Host $host; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
   } }
Copy after login

The above is the detailed content of Website load balancing solution. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:hcoder.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template