Nginx配置实现四层和七层的负载均衡

一、实现http七层的负载均衡

我们都知道Nginx支持七层的负载均衡,能把外部http请求转发到内网的多台服务器,从而实现高可用,这个在项目中很常见,很多人也都会配置,我们举个简单的例子:

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 {
            

猜你喜欢

转载自blog.csdn.net/dragonpeng2008/article/details/130026767