无法访问Docker上NginX反向代理后面的Kibana

q5iwbnjs  于 2022-11-21  发布在  Nginx
关注(0)|答案(4)|浏览(244)

我有一个Docker合成设置与NginX,ElasticSearch和Kibana如下:

web:
    build:
      context: .
      dockerfile: ./system/docker/development/web.Dockerfile
    depends_on:
      - app
    volumes:
      - './system/ssl:/etc/ssl/certs'
    networks:
      - mynet
    ports:
      - 80:80
      - 443:443

  elasticsearch_1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: "${COMPOSE_PROJECT_NAME:-service}_elasticsearch_1"
    environment:
      - node.name=elasticsearch_1
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=elasticsearch_2,elasticsearch_3
      - cluster.initial_master_nodes=elasticsearch_1,elasticsearch_2,elasticsearch_3
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es_volume_1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - mynet

  elasticsearch_2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: "${COMPOSE_PROJECT_NAME:-service}_elasticsearch_2"
    environment:
      - node.name=elasticsearch_2
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=elasticsearch_1,elasticsearch_3
      - cluster.initial_master_nodes=elasticsearch_1,elasticsearch_2,elasticsearch_3
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es_volume_2:/usr/share/elasticsearch/data
    ports:
      - 9201:9201
    networks:
      - mynet

  elasticsearch_3:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
    container_name: "${COMPOSE_PROJECT_NAME:-service}_elasticsearch_3"
    environment:
      - node.name=elasticsearch_3
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=elasticsearch_1,elasticsearch_2
      - cluster.initial_master_nodes=elasticsearch_1,elasticsearch_2,elasticsearch_3
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es_volume_3:/usr/share/elasticsearch/data
    ports:
      - 9202:9202
    networks:
      - mynet

  kibana:
    image: docker.elastic.co/kibana/kibana:7.7.0
    container_name: "${COMPOSE_PROJECT_NAME:-service}_kibana"
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://elasticsearch_1:9200
      ELASTICSEARCH_HOSTS: http://elasticsearch_1:9200
    networks:
      - mynet
      
volumes:
  es_volume_1: null
  es_volume_2: null
  es_volume_3: null

networks:
  mynet:
    driver: bridge
    ipam:
      config:
      - subnet: 172.18.0.0/24
        gateway: 172.18.0.1

下面是我的NginX配置:

server {
   listen 80;
   listen 443 ssl http2;

   ssl_certificate /ssl/localhost.crt;
   ssl_certificate_key /ssl/localhost.key;

  ...

  location /app/kibana {
     proxy_pass http://kibana: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;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header Connection "Keep-Alive";
     proxy_set_header Proxy-Connection "Keep-Alive";
     proxy_set_header Authorization "";
  }

   location ~ /\. {    
      deny all;  
   }
   
   ...
}

当我尝试使用http://localhost/app/kibana访问Kibana时,我看到一个空白页面,并且我能够在浏览器控制台中看到错误:
第一个
如果我将下面的location添加到我的NginX配置中,UI开始显示,但是页面仍然没有响应:

location ~ (/app|/translations|/node_modules|/built_assets/|/bundles|/es_admin|/plugins|/api|/ui|/elasticsearch|/spaces/enter) {
         proxy_pass          http://kibana:5601;
         proxy_set_header    Host $host;
         proxy_set_header    X-Real-IP $remote_addr;
         proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header    X-Forwarded-Proto $scheme;
         proxy_set_header    X-Forwarded-Host $http_host;
         proxy_set_header    Authorization "";
         proxy_hide_header   Authorization;
  }

并且浏览器控制台中存在其他错误:
第一个

wvt8vs2t

wvt8vs2t1#

这个NginX配置对我的Kibana很有效(尽管它给我的其他应用带来了问题):

location /app/kibana/ {
  proxy_pass http://kibana:5601;
}

location ~ (/app|/api|/internal|/translations|/bundles|/ui|/built_assets/|/elasticsearch|/spaces/enter) {
      proxy_pass          http://kibana:5601;
      proxy_set_header    Host $host;
      proxy_set_header    X-Real-IP $remote_addr;
      proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header    X-Forwarded-Proto $scheme;
      proxy_set_header    X-Forwarded-Host $http_host;
      proxy_set_header    Authorization "";
      proxy_hide_header   Authorization;
  }

我发现在第二个location中也需要处理internal。感谢@mikezter帮助清理第一个中的杂乱。

8mmmxcuj

8mmmxcuj2#

现在首选使用简单的容器名称。container_name: "${COMPOSE_PROJECT_NAME:-service}_kibana"改为container_name: "kibana"。您可以稍后更改这些名称,但记住也要更新该名称的所有引用(例如Nginx配置中的Kibana上游主机或Kibana的ELASTICSEARCH_HOSTS配置)。
唯一需要在您的实际机器上打开端口的容器是带有Nginx的web容器。删除所有其他ports: xxxx:yyyyMap。
对于Nginx配置,只需要一个简单的location指令:

location / {
     proxy_pass http://kibana:5601;
}

在不同位置挂载Kibana时,您必须按照此处所述配置Kibana的server.basePath
第一次

k4ymrczo

k4ymrczo3#

对于版本7.16.0,我需要配置SERVER_BASEPATH和SERVERPUBLICBASEURL
第一个

重要提示!:它只是在Firefox中工作(idk为什么)

pkmbmrz7

pkmbmrz74#

我在Kibana上遇到过类似的问题。没有一个答案对我不起作用,但我找到了一个类似的解决方案on this blog post,配置如下:

location ~ (/app|/translations|/node_modules|/built_assets/|/bundles|/es_admin|/plugins|/ui|/elasticsearch|/spaces/enter|/bootstrap.js|/internal|/goto|/api/saved_objects|/api/core|/api/index_patterns|/api/telemetry|/api/metrics|/api/saved_objects_tagging|/api/ui_counters|/api/banners|/api/licensing) {
                     proxy_pass          KIBANA_URL;
                     proxy_set_header    Host $host;
                     proxy_set_header    X-Real-IP $remote_addr;
                     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
                     proxy_set_header    X-Forwarded-Proto $scheme;
                     proxy_set_header    X-Forwarded-Host $http_host;
            }

相关问题