ngx_http_upstream_module

示例:

http上下文:

upstream upservers{
ip_hash; //根据客户端IP进行调度,每个客户端ip地址访问时每个ip生成一个hash码,来自同一个客户端的请求分配到同一个server
   server 192.168.1.102 weight=2;   
   server 192.168.1.103;
}

server端:

proxy_pass http://upservers/;   

健康状况检测:

max_fails=numbers  //检查出的错误次数超过多少次就标记为失败了
fail_timeout=time  //每此检查的超时时长

示例:

 upstream upservers {
  server 192.168.1.102 max_fails=2 fail_timeout=1;
}

如果要对服务器进行更新,可以这么做:

upstream upservers {
  server 192.168.1.103 max_fails= fail_timeout= backup;   //backup: 指定一个服务器为备用服务器 
}

ip_hash是基于源IP进行session绑定

基于sticky进行session绑定:

格式:

Syntax:    sticky cookie name [expires=time] [domain=domain] [httponly] [secure] [path=path];
       sticky route $variable ...;
       sticky learn create=$variable lookup=$variable zone=name:size [timeout=time] [header] [sync];
Default: —
Context: upstream
This directive appeared in version 1.5..

cookie:

upstream backend {
server backend1.example.com;
server backend2.example.com; sticky cookie srv_id expires=1h domain=.example.com path=/;
}

route:

map $cookie_jsessionid $route_cookie {
~.+\.(?P<route>\w+)$ $route;
} map $request_uri $route_uri {
~jsessionid=.+\.(?P<route>\w+)$ $route;
} upstream backend {
server backend1.example.com route=a;
server backend2.example.com route=b; sticky route $route_cookie $route_uri;
}

learn:

upstream backend {
server backend1.example.com:;
server backend2.example.com:; sticky learn
create=$upstream_cookie_examplecookie
lookup=$cookie_examplecookie
zone=client_sessions:1m;
}

least_conn: 调度方法,最少连接

keepalive: 代理服务器和upstream server之间保持连接,一般后端是http server不建议使用,如果是缓存服务器可以考虑

health_check:

  建议:关闭访问日志

自定义响应首部:

add_header X-Via $server_addr;
add_header X-Cache $upstream_cache_status;

nginx模块之ngx_http_upstream_module的更多相关文章

  1. 开发Nginx模块

    开发Nginx模块 前面的哪些话 关于Nginx模块开发的博客资料,网上很多,很多.但是,每篇博客都只提要点,无法"step by step"照着做,对于初次接触Nginx开发的同 ...

  2. nginx 模块介绍

    nginx模块在编译文件下的odjs目录下 cat 查看ngx_modules.c文件 可以看到一些基本extern模块 常用标准模块 1. 性能相关配置 worker_processes numbe ...

  3. nginx 模块简介

    nginx模块一般分为5类:核心模块.标准http模块.可选http模块.邮件服务模块.第三方模块. 其中核心模块和标准http模块在快速编译之后就包含在了nginx中. 主要看一下核心模块.标准ht ...

  4. Nginx模块详解

    Nginx模块介绍 核心模块:core module 标准模块: HTTP modules: Standard HTTP modules Optional HTTP modules Mail modu ...

  5. OpenResty / Nginx模块,Lua库和相关资源的列表

    OpenResty / Nginx模块,Lua库和相关资源的列表 什么是OpenResty OpenResty是一个成熟的网络平台,它集成了标准的Nginx核心,LuaJIT,许多精心编写的Lua库, ...

  6. 手把手教你开发Nginx模块

    前面的哪些话 关于Nginx模块开发的博客资料,网上很多,很多.但是,每篇博客都只提要点,无法"step by step"照着做,对于初次接触Nginx开发的同学,只能像只盲目的蚂 ...

  7. 结合源码看nginx-1.4.0之nginx模块组织结构详解

    目录 0. 摘要 1. nginx模块组织结构 2. nginx模块数据结构 3. nginx模块初始化 4. 一个简单的http模块 5. 小结 6. 参考资料 0. 摘要 nginx有五大优点:模 ...

  8. 【转】Nginx模块开发入门

    转自: http://kb.cnblogs.com/page/98352/ 结论:对Nginx模块开发入门做了一个helloworld的示例,简单易懂.也有一定的深度.值得一看. Nginx模块开发入 ...

  9. Nginx模块开发入门

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

随机推荐

  1. It is possible and safe to monitor a table DML history on sqlserver

    He is my test step: In a test enviroument, I make a table "test"/ demo table:create table ...

  2. 曹工说Spring Boot源码(18)-- Spring AOP源码分析三部曲,终于快讲完了 (aop:config完整解析【下】)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  3. Go语言实现:【剑指offer】数组中重复的数字

    该题目来源于牛客网<剑指offer>专题. 在一个长度为n的数组里的所有数字都在0到n-1的范围内.数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组 ...

  4. EF core (code first) 通过自动迁移实现多租户数据分离 :按Schema分离数据

    前言 本文是多租户系列文章的附加操作文章,如果想查看系列中的其他文章请查看下列文章 主线文章 Asp.net core下利用EF core实现从数据实现多租户(1) Asp.net core下利用EF ...

  5. javascript console对象 常用的方法

    console对象 var o = {name:'3'} console.assert(o.name === '3', "name 的值应该为:string 3"); consol ...

  6. 使用helm安装jenkin和gitlab

    一.使用服务介绍 存储: 阿里云NAS k8s网络插件: calico k8s版本: 1.15.2 二.helm安装 https://www.cnblogs.com/zhangb8042/p/1020 ...

  7. Apache 容器 Directory Location Files 及htaccess文件

    配置段容器的类型 相关模块 core mod_proxy 相关指令 <Directory> <DirectoryMatch> <Files> <FilesMa ...

  8. Error serializing object:序列化对象时出错

    序列化对象时出错 :Error serializing object. Error serializing object. Cause: java.io.NotSerializableExceptio ...

  9. hexo博客

    安装软件 node.js(建议稳定版本,本人安装v8.11.3) npm install -g hexo-cli hexo init myBlog //初始化,在myBlog的文件夹下建立网站 hex ...

  10. Python爬虫beautifulsoup4常用的解析方法总结(新手必看)

    今天小编就为大家分享一篇关于Python爬虫beautifulsoup4常用的解析方法总结,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧摘要 如何用beau ...