nginx 在特定端口上启用身份验证

nginx enable authentication on specific port

我正在尝试使用密码保护我的 Kibana 服务器的 URL。

如果我输入 http://192.168.1.2 in the browser, I am getting prompted for a username/password, but if I query the port 5601 directly via http://192.168.1.2:5601 那么我就可以绕过 nginx 代理验证。

请注意,nginx 和 Kibana 运行 在同一台服务器上。

我尝试了 "localhost"“0.0.0.0”或“127.0.0.1”的不同组合作为监听源地址,但其中 none 有效。我仍然可以轻松绕过代理。

我做错了什么?

这是我的 /etc/nginx/nginx.conf 文件:

server {
  listen 192.168.1.2:80;
  server_name 192.168.1.2;
  location / {
    proxy_pass http://192.168.1.2:5601;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
  }
}

NGINX 仅侦听端口 80,不会阻止对端口 5601 上的应用程序的访问。您应该使用防火墙来阻止对端口本身的访问。你可以:

  1. 将您的服务器放在路由器等防火墙后面(阻止所有外部网络请求)
  2. 在服务器上安装防火墙,例如 UFW。