• nginx 的正向代理 和 反向代理


    正向代理(你自己访问不了 需要借助中间服务器来访问)

    location / {
        proxy_pass http://$http_host$request_uri;
           
    }
    差不多就这样子 我之前的一篇文章里用到了正向代理,一个取百度搜索关键词的应用,里面算是详细,代理很多请求信息什么的

    反向代理:(负载均衡)(自己没资源 需要从其他服务器抓资源)

    worker_processes  1;
    error_log  logs/error.log;
    pid        logs/nginx.pid;
    events {
        worker_connections  1024;
    }
    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;
        keepalive_timeout  65;
            upstream slave_pools{
        server 192.168.11.64:80 weight=1;
    }
        server {
            listen       80;
            server_name  localhost;
            location / {
            proxy_pass  http://39.97.173.13;  # 资源在这个服务器上用
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

     负载均衡

    Nginx要实现负载均衡需要用到proxy_pass代理模块配置
    
    Nginx负载均衡与Nginx代理不同地方在于
    
    Nginx代理仅代理一台服务器,而Nginx负载均衡则是将客户端请求代理转发至一组upstream虚拟服务池
    
    Nginx可以配置代理多台服务器,当一台服务器宕机之后,仍能保持系统可用。
    
    
    
    在nginx.conf > http 区域中
    upstream django {
           server 10.0.0.10:8000;
           server 10.0.0.11:9000;
    }
    
    location / {
                root   html;
                index  index.html index.htm;
                proxy_pass http://django;
    }

    upstream分配策略

    weight 权重
    
    upstream django {
           server 10.0.0.10:8000 weight=5;
           server 10.0.0.11:9000 weight=10;#这个节点访问比率是大于8000的
    }

     

  • 相关阅读:
    SpringCloud之初入江湖
    消息中间件RabbitMQ
    分布式搜索引擎ElasticSearch
    MongoDB简介
    SpringBoot和SpringCloud版本对应
    终于有人把Elasticsearch原理讲透了!
    nginx不停服,重新加载配置
    小程序自定义头部标题栏并且自适应各种手机屏幕(滚动头部渐隐渐现)
    Navicat链接数据库报错1130解决方案
    传统的小程序登录 和 云开发小程序登录
  • 原文地址:https://www.cnblogs.com/niehaidong111/p/11207977.html
Copyright © 2020-2023  润新知