将请求路由到多个后端服务器Dropwizard和Elasticsearch

时间:2022-10-13 13:09:41

I have to backend servers :

我必须后端服务器:

  1. A dropwizard server that serves as a mainly application server. This server is used by the frontend for all operations except searching.
  2. 作为主要应用程序服务器的dropwizard服务器。前端使用此服务器进行除搜索之外的所有操作。

  3. An elasticsearch server feeded by the dropwizard server which serves the frontend for all search queries.
  4. 一个弹性搜索服务器由dropwizard服务器提供,它为所有搜索查询提供前端服务。

Knowing that dropwizard is running on port 8080 and elasticsearch on port 9200, is There any strategy to have a single frontend (nginx for example or apache) that can be used to route search request to elasticsearch and non search request to dropwizard (adding extra headers to distinguish search request or using a different path in the url for search request)?

知道dropwizard在端口8080上运行而弹性搜索在端口9200上运行,是否有任何策略可以使用单个前端(例如nginx或apache)将搜索请求路由到elasticsearch并将非搜索请求路由到dropwizard(添加额外的头文件)区分搜索请求或在网址中使用不同的路径搜索请求)?

I Am open to any suggestion or configuration,

我对任何建议或配置持开放态度,

Thanks in advance,

提前致谢,

1 个解决方案

#1


Nginx configurations

you can proxy them by their own ports:

您可以通过自己的端口代理它们:

server {
  listen 8080;

  location / {
    proxy_pass http://dropwizard-host:8080/;
  }
}

server {
  listen 9200;

  location / {
    proxy_pass http://elasticsearch-host:9200/;
  }
}

Or have them mapped to the same port with different path:

或者将它们映射到具有不同路径的同一端口:

server {
  listen 80;

  location /dropwizard {
    proxy_pass http://dropwizard-host:8080/;
  }

  location /elasticsearch {
    proxy_pass http://elasticsearch-host:9200/;
  }
}

#1


Nginx configurations

you can proxy them by their own ports:

您可以通过自己的端口代理它们:

server {
  listen 8080;

  location / {
    proxy_pass http://dropwizard-host:8080/;
  }
}

server {
  listen 9200;

  location / {
    proxy_pass http://elasticsearch-host:9200/;
  }
}

Or have them mapped to the same port with different path:

或者将它们映射到具有不同路径的同一端口:

server {
  listen 80;

  location /dropwizard {
    proxy_pass http://dropwizard-host:8080/;
  }

  location /elasticsearch {
    proxy_pass http://elasticsearch-host:9200/;
  }
}