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 ...
随机推荐
- python爬虫:一些常用的爬虫技巧
python爬虫:一些常用的爬虫技巧 1.基本抓取网页 get方法: post方法: 2.使用代理IP 在开发爬虫过程中经常会遇到IP被封掉的情况,这时就需要用到代理IP; 在urllib2包中有Pr ...
- c++ oop
C ++语言的主要优势之一是与其前身语言C不同的是,它被设计为支持面向对象编程(OOP). 这是一个相当简单的概念:你将操纵不同的对象,每个对象都是一个特定类的实例. 类是一组方法(绑定到这个类的函数 ...
- ora-02429:无法删除用于强制唯一/主键的索引
今天打算删除orcale数据库中无用的表空间,发现报错,查资料删除,写个过程留着备用. 1.drop tablespace dldata INCLUDING CONTENTS CASCADE CONS ...
- 微软软件开发技术二十年回顾-COM、OLE、ActiveX及COM+篇
本文摘自:http://www.job168.com/info/read_100394.html 微软的许多技术,如OLE.ActiveX.以及DirectX等都是基于COM技术而建立起来的.微软本身 ...
- 书单.md
0823 John Hoskin, An Ilustrated History of Thailand.Asia Books Co., Ltd.2015 0729 Gerald Graff, Cath ...
- Python—判断变量的基本类型
type() >>> type(123)==type(456) True >>> type(123)==int True >>> type('ab ...
- uiautomator跑安卓端UI testing
用uiautomator做安卓的app端的UI testing的环境搭建及编jar包和运行case的步骤如下: 1.新建java工程 2.右键properties, 添加junit4的library, ...
- Huffman编码
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstri ...
- notepad++ 离线插件下载
http://www.cnblogs.com/findumars/p/5180562.html
- Android开发学习---使用Intelij idea 13.1 进行android 开发
1.为什么放弃eclipse?太卡!! 实在受不了eclipse的卡了,运行WEB项目还好,但android开发实在太慢,太慢!经常卡死,CPU经常被占满! 看网上很多人都说比Intelij idea ...