当前位置: 首页 > elasticsearch, 搜索 > 正文

使用nginx做elasticsearch的proxy

关键字:
1 星2 星3 星4 星5 星 (2 次投票, 评分: 5.00, 总分: 5)
Loading ... Loading ...
baidu_share

nginx与elasticsearch配置

方式1.

cd /usr/local/nginx/conf
vi upstream.conf
内容:
upstream search.medcl.com {
                 server localhost:9200;
}

nginx.conf http节点里面:
include upstream.conf;
使用vhost创建子站点:search.medcl.com
方式2(推荐,灵活).

 
location /search {
              proxy_pass    http://localhost:9200/_search;
              proxy_redirect default ;
}
 
location /_search {
              proxy_pass    http://localhost:9200/_search;
              proxy_redirect default ;
}

拒绝请求

 
if ($request_method = 'DELETE' ) {
        return 405;
    }
 
 
 if ($request_method = 'PUT' ) {
        return 405;
    }

当时想限制下请求的传递的size大小的,貌似没有成功,以下是当时的流式账。。。
添加配置:

rewrite  ^/search  /search?q=$arg_q&from=$arg_from&size=$arg_size?  permanent;
 location /search1?from=$1&size=$2 last {
 
           #max size is 199
           if($arg_size ~* "^(1\d{0,2}|\d{0,2})$")
           {
              proxy_pass    http://localhost:9200/_search last;
              proxy_redirect default ;
           }else{
              proxy_pass    http://localhost:9200/_search?from=$arg_from&size=10? last;
              proxy_redirect default ;
           }
}
 
 
 
 location /_search?from=$1&size=$2 last {
              proxy_pass    http://localhost:9200/_search?from=$1&size=$2 last;
              proxy_redirect default ;
 }

本文固定链接: http://www.chepoo.com/nginx-elasticsearch-proxy.html | IT技术精华网

使用nginx做elasticsearch的proxy:等您坐沙发呢!

发表评论