您当前的位置: 首页 >  负载均衡

江湖有缘

暂无认证

  • 0浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Nginx的反向代理与负载均衡

江湖有缘 发布时间:2021-05-10 02:06:16 ,浏览量:0

Nginx的反向代理详解
  • 一、反向代理及相关概念
  • 二、环境说明
  • 二、测试nginx服务
    • 1.测试服务开启状态
    • 2.测试客户端访问nginx的文web是否正常
  • 三、配置反向代理
    • 1.配置nginx.conf
    • 2.测试node2和node3的web服务器状态
  • 四、测试反向代理与负载均衡

一、反向代理及相关概念

正向代理::通常的代理服务器,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器中。 反向代理:代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。 负载均衡: 负载均衡是扩展应用程序并提高其性能和冗余的绝佳方法。在负载 均衡配置中,nginx充当在多个单独服务器上工作的分布式Web应用程序的单个入口点。 在这里插入图片描述 补充理解 反向代理:用户访问服务器,服务器知道客户信息,客户不知道服务器信息,理解为隐藏服务端。 正向代理:用户访问服务器,服务器不知道客户信息,客户知道服务器信息,理解为隐藏客户端。

二、环境说明

node1:作为代理服务器 node2:作为web+server01 node3:作为web+server02 control:作为客户端进行测试

二、测试nginx服务 1.测试服务开启状态
[root@node1 ~]# systemctl status nginx.service 
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-05-09 23:22:15 CST; 2min 4s ago
  Process: 881 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 900 (nginx)
    Tasks: 2 (limit: 12404)
   Memory: 2.5M
   CGroup: /system.slice/nginx.service
           ├─900 nginx: master process /usr/local/nginx/sbin/nginx
           └─901 nginx: worker process

May 09 23:22:14 node1 systemd[1]: Starting nginx...
May 09 23:22:15 node1 systemd[1]: Started nginx.

2.测试客户端访问nginx的文web是否正常

在这里插入图片描述

三、配置反向代理 1.配置nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream web {
       server 192.168.200.136;
       server 192.168.200.133;
        }
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://web;
          }
        }


2.测试node2和node3的web服务器状态
[root@control ansible]# curl node2
welcome to node2.exampel.com!
[root@control ansible]# curl node3
welcome to node3.exampel.com!

四、测试反向代理与负载均衡
[root@control ansible]# 
[root@control ansible]# curl node2
welcome to node2.exampel.com!
[root@control ansible]# curl node3
welcome to node3.exampel.com!
[root@control ansible]# curl node1
welcome to node3.exampel.com!
[root@control ansible]# curl node1
welcome to node2.exampel.com!
[root@control ansible]# curl node1
welcome to node3.exampel.com!
[root@control ansible]# curl node1
welcome to node2.exampel.com!
[root@control ansible]# curl node1
welcome to node3.exampel.com!
[root@control ansible]# curl node1
welcome to node2.exampel.com!
[root@control ansible]# curl node1
welcome to node3.exampel.com!
[root@control ansible]# curl node1
welcome to node2.exampel.com!
[root@control ansible]# curl node1
welcome to node3.exampel.com!

关注
打赏
1665849170
查看更多评论
立即登录/注册

微信扫码登录

0.0390s