首页 > 其他分享 >cerebro+openresty拦截

cerebro+openresty拦截

时间:2023-08-18 11:31:36浏览次数:25  
标签:log conf cerebro 403 proxy openresty 拦截 location

通过openresty拦截掉危险的操作。


配置文件如下:

$ cat docker-compose.yaml 
version: '3'
networks:
    monitor:
        driver: bridge
services:
    cerebro:
        image: lmenezes/cerebro
        container_name: cerebro
        hostname: cerebro
        restart: always
        ports:
            - "1234:9000"
        networks:
            - monitor
    openresty:
        image: openresty/openresty
        container_name: openresty
        hostname: openresty
        restart: always
        ports:
            - "1235:80"
        volumes:
            - ./ngx_conf/nginx.conf:/etc/nginx/nginx.conf
            - ./ngx_conf/cerebro.conf:/etc/nginx/conf.d/cerebro.conf
        networks:
            - monitor


mkdir ngx_conf

cd ngx_conf

2个配置文件如下:

$ cat nginx.conf 
user nginx;
worker_processes  4;

#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 {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    
    access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  120;


    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 32k;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    gzip_vary on;
    gzip_proxied any;
    gzip_disable "MSIE [1-6]\.";

    proxy_buffer_size 8k;
    proxy_buffering on;
    client_header_buffer_size 8k;
    client_body_buffer_size 8k;
    proxy_request_buffering on;
    proxy_cache_lock on;
    proxy_cache_use_stale updating;

    include /etc/nginx/conf.d/*.conf;
}



$ cat cerebro.conf 
server {
  listen 80;
  #error_log /var/log/nginx/cerebro_proxy_err.log;

  root /usr/share/nginx/html;

  location / {
  default_type application/json;
        proxy_pass http://cerebro:9000;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  }

  # overview界面的危险操作全部拦截掉
  location /cluster_settings {
    return 403;
  }
  location ~ (/templates|/commons/indices|/disable_shard_allocation|/analysis) {
    return 403;
  }
  location /overview/relocate_shard {
    return 403;
  }
  location /overview/delete_indices {
    return 403;
  }
  location /overview/close_indices {
    return 403;
  }
  location /overview/force_merge {
    return 403;
  }
  location /overview/flush_indices {
    return 403;
  }
  location /overview/refresh_indices {
    return 403;
  }
  location /overview/clear_indices_cache {
    return 403;
  }
  
  # 对于rest界面的请求进行的拦截
  location /rest/request {
  default_type application/json;

  lua_need_request_body on;
  access_by_lua_block {
    local data1 = ngx.req.get_body_data()

    -- 拦截纯DELETE操作
    result1 = string.match(data1, "DELETE")
    if result1 == "DELETE" then
      ngx.exit(403)
    end

    -- 拦截_delete_by_query并且是match_all的操作
    result2 = string.match(data1, "_delete_by_query")
    result3 = string.match(data1, "match_all")
    result4 = string.match(data1, "POST")
    if result2 == "_delete_by_query" and result3 == "match_all" and result4 == "POST" then
      ngx.exit(403)
    end
  }

  proxy_pass http://cerebro:9000;
  proxy_set_header   Host             $host;
  proxy_set_header   X-Real-IP        $remote_addr;
  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  }

}

标签:log,conf,cerebro,403,proxy,openresty,拦截,location
From: https://blog.51cto.com/lee90/7133267

相关文章

  • mybatis自定义拦截器@Intercepts
    mybatis:自定义实现拦截器插件Interceptor-知乎(zhihu.com) 11.插件机制Interceptor|一灰灰Learning(hhui.top)......
  • 浅谈拦截器和过滤器
    在Java中,拦截器(Interceptor)是一种用于拦截和处理请求的组件。它可以在请求被处理前和处理后对请求进行拦截和修改。拦截器通常用于实现一些公共的功能,比如日志记录、权限验证、性能监控等。下面是一个简单的Java拦截器示例代码:1publicclassLoggingInterceptorimplements......
  • 高性能OpenResty与多级缓存架构
    一个系统架构要支持高并发与高性能,那么必然会借助很多的资源以及中间件来共同配合实现。平时我们用的最多的是分布式缓存Redis,万金油中间件,性能很高,适用场景也很多,但是会受限与容器,springboot单个容器运行在tomcat中,而tomcat的并发也就150~200上下,可以支撑十几万并发的redis很显然......
  • 【JavaScript42】axios拦截器
    在前端,我们能看到有些网站会对每次请求都添加加密信息.或者每次返回数据的时候,都有解密逻辑.那此时.你思考.不可能每次请求都要程序员去手动写加密逻辑.axios提供了拦截器.可以对每一个请求进行拦截.并修改请求的内容.拦截器还可以对响应进行拦截.并修改响应的数据.......
  • openresty(nginx)、lua、drizzle测试
    一、概述:1.研究目标:nginx中使用lua脚本,及nginx直接访问mysql,redis2.需要安装的内容:openresty,mysql,redis3.OpenResty(也称为ngx_openresty)是一个全功能的Web应用服务器。它打包了标准的Nginx核心,很多的常用的第三方模块,以及它们的大多数依赖项。http://openresty.org/cn/ind......
  • quarkus依赖注入之十一:拦截器高级特性上篇(属性设置和重复使用)
    欢迎访问我的GitHub这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos本篇概览本篇是《quarkus依赖注入》系列的第十一篇,之前的[《拦截器》]学习了拦截器的基础知识,现在咱们要更加深入的了解拦截器,掌握两种高级用法:拦截器属性和重复使用拦截......
  • spring-mvc 系列:拦截器和异常处理器
    目录一、拦截器的配置二、拦截器的三个抽象方法三、多个拦截器的执行顺序四、基于配置的异常处理器五、基于注解的异常处理器一、拦截器的配置SpringMVC中的拦截器用于拦截控制器方法的执行SpringMVC中的拦截器需要实现HandlerInterceptorSpringMVC的拦截器必须在SpringMVC的......
  • 全局设置axios拦截器,请求增加username和token
    在main.js的newvue之前加入:axios.interceptors.request.use(config=>{//在发送请求前,获取新的tokenvarusername=window.localStorage.getItem('username');varauthorization=window.localStorage.getItem('token');......
  • axios 请求拦截(request)与响应拦截(response)
    1.请求拦截(request)请求拦截就是在发ajax之前做些什么!例如:可以在请求拦截里面加个token请求头,做些判断等等!语法:axios.interceptors.request.use((config)=>{},(error)=>{})1.1.参数1:(config)=>{}请求正确走的函数1.2.参数2:(error)=>{}请求错误走的函数1.3.代码案......
  • 如何将 dubbo filter 拦截器原理运用到日志拦截器中?
    业务背景我们希望可以在使用日志拦截器时,定义属于自己的拦截器方法。实现的方式有很多种,我们分别来看一下。拓展阅读java注解结合springaop实现自动输出日志java注解结合springaop实现日志traceId唯一标识java注解结合springaop自动输出日志新增拦截器与过滤器......