反向代理 正向代理 正向代理和反向代理的区别和区分: 1、轮询 rr 全称 round robin 2、加权轮询(wrr weight round robin) 3、ip_hash 4、fair 5、url_hash 其中,hash_method为使用的hash算法,需要注意的是:此时,server语句中不能加weight等参数。 关于反向代理的几个配置项 反向代理的几个参数 主机情况 思路: 使用反向代理服务器代理web1和web2 当有请求到达反向代理服务器时 请求会被分发到后端两个web服务器上 为了让效果更加明显 我们此处使用轮询的调度算法 修改反向代理服务器的配置 启动nginx(如果已经启动过 则reload) 访问代理服务器的ip进行测试 可以出现轮询则证明实验成功 通过location的设置 可以实现访问资源的动静分离 主机情况 说明: 此处我们将基于lamp搭建的论坛 作为动态数据处理的服务器 而web2作为静态数据处理的服务器 web1的论坛的首页如下图 修改代理服务器的配置 经过上述的设置 当代理服务器接收到对html等静态资源的请求时 会转发给20.128 接收到php页面的请求时 会转发给20.133 检测语法并重载nginx 访问测试 分别访问两种页面 看是否会进行动静分离
1. nginx反向代理
1.1 代理的分类
(Reverse Proxy)方式是指以代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器;并将从服务器上得到的结果返回给Internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。
通常的代理服务器,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器中。当一个代理服务器能够代理外部网络上的主机,访问内部网络时,这种代理服务的方式称为反向代理服务
敏感,省略了
从代理服务器的作用来看 ,正向代理的作用是代理客户端的请求 帮助客户端获取想要的内容。反向代理的作用是 代理企业内部的服务器 接收网络上的请求 并进行负载的分散 降低服务器压力。1.2 nginx反向代理的算法和参数
轮询是upstream的默认分配方式,即每个请求按照时间顺序轮流分配到不同的后端服务器,如果
某个后端服务器down掉后,能自动剔除。 upstream backend { server 192.168.1.101:8888; server 192.168.1.102:8888; server 192.168.1.103:8888; }
轮询的加强版,即可以指定轮询比率,weight与访问几率成正比,主要应用于后端服务器异
质的场景下。 upstream backend { server 192.168.1.101 weight=1; server 192.168.1.102 weight=2; server 192.168.1.103 weight=3; }
每个请求按照访问ip(即Nginx的前置服务器或者客户端IP)的hash结果分配,这样每个访客会固
定访问一个后端服务器,可以解决session一致问题。 upstream backend { ip_hash; server 192.168.1.101:7777; server 192.168.1.102:8888; server 192.168.1.103:9999; }
fair顾名思义,公平地按照后端服务器的响应时间(rt)来分配请求,响应时间短即rt小的后端
服务器优先分配请求。 upstream backend { server 192.168.1.101; server 192.168.1.102; server 192.168.1.103; fair; }
与ip_hash类似,但是按照访问url的hash结果来分配请求,使得每个url定向到同一个后端服务
器,主要应用于后端服务器为缓存时的场景下。 upstream backend { server 192.168.1.101; server 192.168.1.102; server 192.168.1.103; hash $request_url; hash_method crc32; }
upstream name { ip_hash; server 192.168.1.100:8000; server 192.168.1.100:8001 down; server 192.168.1.100:8002 backup; server 192.168.1.100:8004 max_fails=3 fail_timeout=20s; }
1.3 nginx反向代理实战操作
角色
ip
反向代理服务器 nginx
192.168.20.129
web服务器1号 httpd
192.168.20.133
web服务器2号 httpd
192.168.20.128
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf 在server的上一行添加upstream upstream webcluster { server 192.168.20.133:80 max_fails=3 fail_timeout=20s; server 192.168.20.128:80 max_fails=3 fail_timeout=20s; } 修改默认的location的配置 修改完之后location如下 location / { root html; index index.html index.htm; proxy_pass https://webcluster; proxy_send_timeout 900s; proxy_read_timeout 900s; proxy_connect_timeout 900s; proxy_buffer_size 32k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_set_header Host $host; proxy_set_header Referer $http_referer; proxy_set_header Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
[root@localhost ~]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@localhost ~]# nginx nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) ^C [root@localhost ~]# nginx -s reload
2. 动静分离
角色
ip
反向代理服务器 nginx
192.168.20.129
web服务器1号 lamp
192.168.20.133
web服务器2号 nginx
192.168.20.128
web2的首页如下图[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf 在默认的location上添加两个location location ~ .php$ { proxy_pass https://192.168.20.133; } location ~ .(html|htm|jpg|png|jpeg)$ { proxy_pass https://192.168.20.128; }
[root@localhost ~]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@localhost ~]# nginx -s reload
https://192.168.20.129/index.html
https://192.168.20.129/index.php
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算