使用Nginx作为代理来防止通过JavaScript客户端在ElasticSearch上创建/更新/删除操作

Fla*_*lsi 6 proxy nginx elasticsearch

我有一个本地ElasticSearch服务器,由Nginx公开,可以防止POST,PUT和DELETE请求.这是我的Nginx配置足以防止信息获取之外的操作?你建议改进吗?

  upstream elasticsearch {
      server localhost:9200;
  }

  server {
      listen 7777;

      location / {
        return 403;
        limit_except PUT POST DELETE {
          proxy_pass http://elasticsearch;
        }
        proxy_redirect off;
      }

  }
Run Code Online (Sandbox Code Playgroud)

谢谢.

[UPDATE]

我的配置在deagh的建议之后:

  upstream elasticsearch {
      server localhost:9200;
  }

  server {
      listen 7777;

      location / {
        return 403;
        limit_except PUT POST DELETE {
          proxy_pass http://elasticsearch;
        }
        proxy_redirect off;
      }

      location ~* ^(/_cluster|/_nodes|/_shutdown) {
        return 403;
        break;
      }

  }
Run Code Online (Sandbox Code Playgroud)

小智 4

您还应该注意与不同 elasticsearch 位置的连接,例如

  • _簇
  • _节点
  • _关闭

您可以在文档中找到有关 nginx 和 elasticsearch 的工作(和安全)设置的更多信息 => http://www.elasticsearch.org/blog/playing-http-tricks-nginx/