美文网首页web前端
反向代理与负载均衡

反向代理与负载均衡

作者: 姜治宇 | 来源:发表于2022-05-23 21:00 被阅读0次

反向代理

当客户端输入一个网址时,先需要进行dns解析,找到对应的ip服务器地址,到达nginx服务器,然后nginx服务器将请求转发到相应的node应用服务器。
当node服务器处理完请求后,将资源返回到nginx服务器,然后由nginx将资源再回传给客户端。
从这个过程可以看出,nginx本身不处理业务,只是充当了中介代理的作用,因此叫反向代理。
nginx配置反向代理非常简单,利用proxy_pass可以配置代理服务器,可以是http://www.site.com这样的域名,也可以是ip地址。

worker_processes  1;
events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://192.168.1.133; #如果是域名一定要带www,否则会是302,不支持https
            # root   html; #配置了反向代理proxy_pass,root这些就没用了
            # index  index.html index.htm;
        }

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

    }

}

负载均衡

常用的负载均衡策略是轮询,配置高的主机可以给予较高权重,这样轮询的次数也会增加。

worker_processes  1;
events {
    worker_connections  1024;
}


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

    upstream mysite {
       server 192.168.1.100 weight=8;
       server 192.168.1.101 weight=3;
      server 192.168.1.102  weight=1 backup;  #备份服务器,当前面两台服务器崩掉后转发到这里
      
    }
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://mysite; #随便起名
            #root   html;
            #index  index.html index.htm;
        }

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

    }

}

相关文章

  • Linux运维-day56/57-负载均衡之lvs

    一、负载均衡与反向代理的区别 1.1 功能(原理) 负载均衡lvs---请求做转发 反向代理Nginx Hapro...

  • 负载均衡与lvs

    一、负载均衡与反向代理的区别 1.1 功能(原理) 负载均衡lvs---请求做转发 反向代理Nginx Hapro...

  • 4.常用配置

    反向代理 负载均衡 FastCGI 负载均衡详细配置

  • 负载均衡之lvs

    1.负载均衡 VS 反向代理区别 1.1 功能(原理) 负载均衡 lvs 请求做转发 反向代理 Nginx Hap...

  • 3.Nginx的反向代理

    nginx反向代理 反向代理就是负载均衡负载均衡分为四层负载和七层负载四层负载:基于IP+端口的负载七层负载:基于...

  • linux学习--week17--nginx-lnmp

    负载均衡2.1 负载均衡与反向代理区别2.2nginx 7层负载2.3 nginx 7层负载2.4 nginx 4...

  • 【转】浅谈Nginx之反向代理与负载均衡

    Nginx的负载均衡是基于反向代理实现的,因此,本文先讨论什么是反向代理,再在这个的基础上讨论负载均衡以及负载均衡...

  • 使用nginx对spring boot项目进行代理

    摘要:使用nginx对spring boot项目进行反向代理,并且使用轮询均衡负载策略 均衡负载与集群 集群和均衡...

  • 【Nginx】实现负载均衡的几种方式

    要理解负载均衡,必须先搞清楚正向代理和反向代理。 正向代理与反向代理【总结】 注: 正向代理,代理的是用户。反向代...

  • Nginx源码学习——负载均衡

    什么是负载均衡器? 了解负载均衡器前,需要知道什么是“反向代理”?反向代理(reverse proxy) 是指用代...

网友评论

    本文标题:反向代理与负载均衡

    本文链接:https://www.haomeiwen.com/subject/nphdprtx.html