【问题标题】:Docker can not up Nginx and Nginx htpasswd never detectingDocker 无法启动 Nginx 和 Nginx htpasswd 从不检测
【发布时间】:2019-03-22 08:54:16
【问题描述】:

您好,我正在尝试使用 Docker 建立 ELK 堆栈 + Nginx(用于负载平衡和基本身份验证)。我的问题是:我无法使用 Nginx 作为负载均衡器,当我尝试访问 kibana web ui 时,从不向我询问任何密码。如何重新排列我的 docker compose 以实现安全性和负载平衡?我正在使用 Windows 10。

我的文件结构如下:

我的 docker-compose.yml:

version: '2'
 services:
 elasticsearch:
container_name: esc
image: esi:1.0.0
build: ./es
volumes:
  - ./data/es:/usr/share/elasticsearch/data
ports:
    - 9200:9200
expose:
    - 9300
kibana:
container_name: kibanac
image: kibanai:1.0.0
build: ./kibana
links:
  - elasticsearch
ports:
  - 5601:5601
nginx:
image: nginx:latest
restart: unless-stopped
volumes:
  - ./nginx/config:/etc/nginx/conf.d:ro,Z
  - ./nginx/htpasswd.users:/etc/nginx/htpasswd.users:ro,Z
ports:
  - "8890:8890"
depends_on:
  - elasticsearch
  - kibana

Docker 守护进程:

Nginx.conf:

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

 upstream kibana {
server localhost:5601;
keepalive 15;
 }

server {
listen 8888;

location / {
  auth_basic           "Protected Elasticsearch";
  auth_basic_user_file /etc/nginx/htpasswd.users;

  proxy_pass http://localhost:9200;
  proxy_redirect off;
  proxy_buffering off;

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

}

 server {
 listen 8889;

 location / {
  auth_basic           "Protected Kibana";
  auth_basic_user_file /etc/nginx/htpasswd.users;

  proxy_pass http://localhost:5601;
  proxy_redirect off;
  proxy_buffering off;

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

}

Kibana.yml:  ( calling for kibana ui-> localhost:5601)

 server.name: kibana
 server.host: "0"
 elasticsearch.url: http://elasticsearch:9200
 elasticsearch.username: elastic
 elasticsearch.password: changeme
 xpack.monitoring.ui.container.elasticsearch.enabled: true

Elasticsearch.yml:  ( calling for elasticsearch-> localhost:9200)

 http.host: 0.0.0.0

 ### x-pack functions
 xpack.security.enabled: false

 xpack.monitoring.enabled: true
 xpack.graph.enabled: false
 xpack.watcher.enabled: false

Dockerfile for Kibana:
FROM docker.elastic.co/kibana/kibana:6.6.2

COPY ./config/kibana.yml /opt/kibana/config/kibana.yml

Dockerfile for Elasticsearch: 
FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.2

COPY ./config/elasticsearch.yml 
/usr/share/elasticsearch/config/elasticsearch.yml

【问题讨论】:

  • 访问 kibana 的 URL 是什么?
  • @ThanhNguyenVan;我为你更新了上面的代码。

标签: docker nginx docker-compose devops elastic-stack


【解决方案1】:

请在您访问 Kibana Web UI 的 nginx 配置中添加 IP 地址或域名。

listen ip_address_or_domain_name:8889; 

和:

proxy_pass http://kibana;

在 docker-compose.yml 文件中:

ports:
  - "8890:8889"

请注意,它的端口是 8889。

访问:http://ip_address_or_domain_name:8890

【讨论】:

    猜你喜欢
    • 2022-01-22
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    相关资源
    最近更新 更多