OpenResty(nginx_lua_module)做ES代理以及备份ES数据
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { upstream master { server 10.1.1.100:9200; server 10.1.1.100:9200 backup; keepalive 15; } upstream slave { server 10.1.1.100:9200; keepalive 15; } server { server_name localhost 127.0.0.1 10.1.1.225; listen 8888; location / { #if ($request_method = "GET") { #proxy_pass http://master; # get直接走upstream master #} content_by_lua_block { local function getFile(file_name) local f = assert(io.open(file_name, 'r')) local string = f:read("*all") f:close() return string end ngx.req.read_body() ngx.log(ngx.ERR, '$$$' ..ngx.var.request_uri .. '$$$') local request_body = ngx.req.get_body_data() if nil == request_body then local file_name = ngx.req.get_body_file() if file_name then request_body = getFile(file_name) end end local master_resp, slave_resp local req_method_constant = ngx['HTTP_' .. ngx.req.get_method()] local arry = {method = req_method_constant, body = request_body} if req_method_constant == ngx.HTTP_POST or req_method_constant == ngx.HTTP_PUT or req_method_constant == ngx.HTTP_DELETE then master_resp, slave_resp = ngx.location.capture_multi{ {'/slave' .. ngx.var.request_uri, arry}, {'/master' .. ngx.var.request_uri, arry} } else master_resp = ngx.location.capture_multi{ {'/master' .. ngx.var.request_uri, arry} } end --[[ 使用master的响应头 --]] for k,v in pairs(master_resp.header) do ngx.header[k] = v end ngx.say(master_resp.body) } } location ~* ^/master { internal; log_subrequest on; rewrite ^/master(.*)$ $1 break; proxy_pass http://master; access_log logs/master.log; } location ~* ^/slave { internal; log_subrequest on; rewrite ^/slave(.*)$ $1 break; proxy_pass http://slave; access_log logs/slave.log; } } }
OpenResty(nginx_lua_module)做ES代理以及备份ES数据的更多相关文章
- es快照和备份
注册前要注意配置文件加上 path.repo: ["/data/es_backup"] 然后重启es 不然会报错doesn't match any of the locations ...
- nginx做正向代理(Centos7,支持http和https)
默认的情况下,使用nginx做正向代理可以解析http请求, 对于诸如baidu.com这样的https请求,nginx默认并不支持,不过我们可以借助第三方模块来实现. 1.先说默认情况下的代理配置 ...
- 用apache做为代理下载本地pdf文件
有一些公司会用apache做为代理,下载服务器上的pdf文件.以下是apache做为代理的配置 一. 环境 centos6.5 192.168.69.3 二. yum安装apache 服务 [zxj ...
- 使用ssh正向连接、反向连接、做socks代理的方法
ssh -L 219.143.16.157:58080:172.21.163.32:8080 用户名@localhost -p 10142 在 219.143.16.157机器执行 将ssh隧 ...
- nginx做反向代理并防盗链
nginx做反向代理真的非常简单,只需设置location+proxy_pass即可. 防盗链配置有些复杂,需要注意的地方: 在防盗链的location中需要再设置一下proxy_pass(在这里走了 ...
- 用nginx做反向代理来访问防外链图片
用nginx做反向代理来访问防外链图片 女儿的博客从新浪搬到wordpress后,发现原来博客上链接的新浪相册的图片都不能访问了,一年的博客内容,一个个去重新上传图片,修正链接也是个大工程.还是得先想 ...
- 【Nginx】使用Nginx做反向代理时,关于被代理服务器相应的超时设置
> 参考的优秀文章 Module ngx_http_proxy_module > 设置等待被代理服务器的最大响应时间 使用Nginx做反向代理时,因被代理服务器因业务确实复杂,需时较久,往 ...
- Nginx做反向代理总是被系统kill
公司使用Nginx做反向代理,以前都挺正常的,最近不知怎么回事总是无端被系统kill,而在nginx错误日志中也没有信息输出. 网上查了很多资料,也没什么靠谱的回答,唯一觉得有点关联的就是linux ...
- nginux做反向代理配置文件
做反向代理的配置文件最好单独创建一个文件,然后在主配置文件中使用 include nginx-test.config; 这样的方式来导入. 配置代码如下: ## Basic reverse prox ...
随机推荐
- Linux系统yum命令安装软件时保留(下载)rpm包 -- 转载
昨天在部署zabbix监控的时候,遇到一个问题:监控服务器处于无外网状态,在线安装不可用.而某些依赖包度娘或谷姐搜索起来也挺呛人的!于是想到一个办法,利用有外网的服务器的yum命令来安装这些软件,并自 ...
- spring mvc学习笔记一:hello world
下面是创建springmvc简单案例的步骤: 项目的目录结构如下: 此案例使用maven构建. 第一步:创建动态web工程,然后项目->configure->convert to mave ...
- javascript 伪协议
[javascript 伪协议] 将javascript代码添加到客户端的方法是把它放置在伪协议说明符javascript:后的URL中.这个特殊的协议类型声明了URL的主体是任意的javascrip ...
- ES 集群
http://www.cnblogs.com/o-andy-o/p/5067184.html
- Git保存密码
TortoiseGit中,通过https方式连接时,默认是不会保存帐号密码,需要我们每次输入一次,真心很麻烦! 通过简单的设置,就可以解决这一问题! 编辑仓库目录中本地的”.git/config”文件 ...
- C# lambda
1. lambda example 1 // Create a basic delegate that squares a number MyDelegate foo = (x) => x * ...
- linux服务器加硬盘扩容
from: http://bbs.chinaunix.net/thread-3613556-1-1.html 试验环境: vmware下,centos6,64位版本,原来系统默认分区,/dev/sda ...
- Shell 去掉文本中的空格
使用sed命令 将文件'aol1'中的空格去掉然后输出到'tmpFile'文件中 sed s/[[:space:]]//g aol1 > tmpFile
- mybatis多表连接在一起查询
实体类 和 xml (这里用了几个典型的数据类型,都是其他表的字段) private String marriage;//图片 remarks private Date createtime;//公告 ...
- Eclipse创建Maven时提示错误could not resolve archetype
今天用Eclipse创建Maven多模块项目的时候提示错误: could not resolve archetype ******release from any of the configured ...