elasticsearch,Angularjs,Security,Nginx,Proxy,elasticsearch" /> elasticsearch,Angularjs,Security,Nginx,Proxy,elasticsearch" />

Angularjs 用于ElasticSearch的Nginx反向代理仅允许_搜索端点

Angularjs 用于ElasticSearch的Nginx反向代理仅允许_搜索端点,angularjs,security,nginx,proxy,elasticsearch,Angularjs,Security,Nginx,Proxy,elasticsearch,我知道如何在这里只允许GET请求更多,但在我的情况下,最好将nginx反向代理配置为只允许搜索端点。我找不到一个方法来做这件事。 有人能帮我吗 为了清楚起见,我将使用angularjs查询elasticsearch。我想尽快完成。我不能让它完全打开,但将查询缩小到搜索点将是完美的。似乎Nginx有能力做到这一点,但我不知道如何做到 必须是配置或正则表达式中的一些if语句,我猜…作为概念证明,我最终得出了这个结论。请不要在没有先检查后果的情况下使用 events { worker_connec

我知道如何在这里只允许GET请求更多,但在我的情况下,最好将nginx反向代理配置为只允许搜索端点。我找不到一个方法来做这件事。 有人能帮我吗

为了清楚起见,我将使用angularjs查询elasticsearch。我想尽快完成。我不能让它完全打开,但将查询缩小到搜索点将是完美的。似乎Nginx有能力做到这一点,但我不知道如何做到


必须是配置或正则表达式中的一些if语句,我猜…

作为概念证明,我最终得出了这个结论。请不要在没有先检查后果的情况下使用

events {
  worker_connections  1024;
}

http {

  upstream elasticsearch {
    server 127.0.0.1:9200;
    keepalive 15;
  }

  server {
    listen: 8080;

    # ES backend for search autocomplete
    # 1. Allow only GET requests.
    # 2. Capture the search_term which cannot contain the " character.
    # 3. Rewrite the request to the desired index's _search elasticsearch endpoint.
    # 4. Build the request body by concatenating the appropriate json with the search_term.
    # 5. proxy_pass the translated request to elasticsearch.
    location ~* ^/search/autocomplete/(?<search_term>[^"]+)$ {
      if ($request_method != GET) {
        return 403;
      }

      proxy_http_version                    1.1;
      proxy_set_header Connection           "Keep-Alive";
      proxy_set_header Proxy-Connection     "Keep-Alive";

      set $search_prefix                    '{"query":{"match":{"user.name":"';
      set $search_suffix                    '"}},"highlight":{"pre_tags":["<strong>"],"post_tags":["</strong>"],"fields":{"user.name":{}}}}';
      set $search                           $search_prefix$search_term$search_suffix;
      proxy_set_body                        $search;

      proxy_redirect                        off;
      proxy_buffering                       off;

      rewrite ^.*$                          /my_index/blogpost/_search break;
      proxy_pass                            http://elasticsearch;
    }

    # All other requests go to the web application server.
    location / {
      proxy_pass                            http://server;
    }

  }

}