Nginx configuration to achieve four-layer and seven-layer load balancing

1. Realize the load balancing of HTTP layer seven

We all know that Nginx supports seven-layer load balancing, and can forward external HTTP requests to multiple servers on the intranet to achieve high availability. This is very common in projects, and many people will configure it. Let's give a simple example:

worker_processes  1;

events {
    worker_connections  1024;
}

http {	
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    upstream nacosserver {
        server 172.16.0.1:8848;
        server 172.16.0.2:8848;    
    }
	
    server {
        listen       80;
        server_name  localhost;

        location / {        	
            root   html;
            index  index.html index.htm;
        }

        location /nacos/ {
    		proxy_pass_header Server;
    		proxy_set_header Host $http_host;
   			proxy_set_header X-Real-IP $remote_addr;
    		proxy_set_header X-Scheme $scheme;
    		proxy_pass http://nacosserver/nacos/;
		}


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            

Guess you like

Origin blog.csdn.net/dragonpeng2008/article/details/130026767