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 ...
随机推荐
- JavaScript 中this与Dom中的注意
对于下面这段代码: <script type='text/javascript'> function testThis() { console.log(this); } </scri ...
- 问题1:Mybatis 中 Signature中的参数args 问题2:MetaObject中 forObject方法中的参数
1.@Intercepts({@Signature(type =StatementHandler.class, method = "prepare", args ={Connect ...
- MySQL大数据量快速分页实现(转载)
在mysql中如果是小数据量分页我们直接使用limit x,y即可,但是如果千万数据使用这样你无法正常使用分页功能了,那么大数据量要如何构造sql查询分页呢? 般刚开始学SQL语句的时候,会这 ...
- nullcon HackIM 2016 -- Programming Question 5
Dont blink your Eyes, you might miss it. But the fatigue and exhaustion rules out any logic, any wil ...
- PL/SQL EO 设计与开发
1.INSERT 调用PL/SQL 去insert的时候,没有使用super(),此时应当自己创建callable statement: 调用checkErrors()方法在执行 callable s ...
- scala 学习之: list.fill 用法
题目描述: Decode a run-length encoded list. Given a run-length code list generated as specified in probl ...
- iOS错误总结(三)
1.如果tableView设置为分组的样式(默认是有cell之间的分割线,可以设置颜色),默认有组以及组尾的高度 需要手动在组头组尾的代理方法中进行组高的设置(如果想设置为0,最好写0.01) 2.组 ...
- 绘制相切弧arcTo
绘制相切弧 语法: CanvasRenderingContext2D.arcTo( x1, y1, x2, y2, radius ) 描述: 该方法用于绘制圆弧 绘制的规则是当前位置与第一个参考点连线 ...
- oracle exp imp 导入 正在跳过表 plsql 导入表 成功终止 数据 被导入
http://blog.csdn.net/agileclipse/article/details/12968011 .导入过程中,所有表导入都出现提示, 正在跳过表...某某表名 最后提示成功终止导入 ...
- Validate US Telephone Numbers
function telephoneCheck(str) { // Good luck! //return true; var phone = /^1? ?(\d{3}|\(\d{3}\))[ -]? ...