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

本地搭建Nginx反向代理Kibana失败,elastic.local访问超时无响应

问题排查与解决步骤

1. 解决elastic.local访问超时问题

超时核心原因是域名没有正确解析到你Ubuntu虚拟机的IP,按访问场景配置:

  • 如果你在虚拟机本地访问elastic.local:
    编辑/etc/hosts文件,添加如下记录:
    127.0.0.1 elastic.local
    
  • 如果你在宿主机/其他设备访问虚拟机的elastic.local:
    编辑对应设备的hosts文件(Windows路径为C:\Windows\System32\drivers\etc\hosts,macOS/Linux路径为/etc/hosts),添加如下记录:
    你的Ubuntu虚拟机实际IP elastic.local
    
    同时要确保虚拟机80端口未被防火墙拦截,执行命令放行:
    sudo ufw allow 80/tcp
    

2. 解决127.0.0.1:80访问无认证问题

该现象是因为你配置的server块只匹配Host头为elastic.local的请求,访问127.0.0.1时Nginx命中了默认的无认证server配置。直接修改你的Nginx配置即可:
编辑/etc/nginx/sites-available/default文件,将server块调整为如下内容:

server {
    listen 80 default_server;
    # 可按需调整匹配的域名,不需要匹配127.0.0.1可删掉后面的参数
    server_name elastic.local 127.0.0.1;

    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/htpasswd.users;

    location / {
        proxy_pass http://localhost:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;        
    }
}

配置校验与生效

  • 先确认htpasswd.users文件已正确生成,未生成的话执行如下命令创建(需先安装依赖工具):
    sudo apt install apache2-utils -y
    sudo htpasswd -c /etc/nginx/htpasswd.users 自定义用户名
    
    按提示输入密码即可。
  • 校验Nginx配置语法是否正确:
    sudo nginx -t
    
    输出提示test is successful后执行重载命令生效:
    sudo systemctl reload nginx
    

效果验证

配置完成后,访问http://elastic.local会先弹出身份验证框,输入你设置的用户名密码后即可正常访问Kibana。

内容的提问来源于stack exchange,提问作者Amine Ch 99

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 20:51:01