You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch通过NGINX反向代理返回index_not_found_exception求助

问题:Nginx反向代理Elasticsearch返回index_not_found_exception错误

我直接发送GET请求能获取有效的Elasticsearch响应,但通过自建的NGINX反向代理访问myip/elasticsearch时,却返回index_not_found_exception错误。以下是我的NGINX配置,恳请帮忙排查:

server { 
listen 80; 
server_name myip; 
location /elasticsearch/ { 
proxy_pass http://127.0.0.1:9200; 
} 
location /kibana/ { 
proxy_pass http://127.0.0.1:5601; 
} 
}

问题原因与解决办法

这问题我之前也碰到过,核心是Nginx的路径拼接规则搞的鬼!

  • 错误根源:你配置里的location /elasticsearch/结尾带了斜杠,但proxy_pass的地址没加斜杠。当你访问myip/elasticsearch/_cat/indices时,Nginx会把整个前缀后的路径拼到目标地址后面,转成http://127.0.0.1:9200/elasticsearch/_cat/indices——Elasticsearch会把elasticsearch当成一个不存在的索引名,自然就返回索引找不到的错误了。

  • 修复配置:给proxy_pass的地址末尾加上斜杠,让Nginx正确剥离请求前缀:

location /elasticsearch/ { 
proxy_pass http://127.0.0.1:9200/; 
} 

改完之后,访问myip/elasticsearch/_cat/indices就会被转发到http://127.0.0.1:9200/_cat/indices,和你直接访问Elasticsearch的路径完全一致,就能拿到正常响应了。

  • 顺带优化Kibana代理:Kibana的配置也建议同步加上末尾的斜杠,避免后续出现类似的路径问题:
location /kibana/ { 
proxy_pass http://127.0.0.1:5601/; 
} 

内容的提问来源于stack exchange,提问作者LEE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 14:12:31