Kibana 5.5.1后面的一个nginx 1.13代理(dockerized)
目标:
我想在Docker容器中运行麋鹿堆栈。 为了能够通过nginx代理访问ELK栈来绕过服务的各个端口。
Kibana服务(默认端口5601)
http://<server>.com:5601
应通过以下地址可达:
http://<server>.com/kibana
问题:
问题是,在将server.basePath设置添加到configuration后,无法到达kibana站点。 如果我将Kibana的每个base API调用添加到nginxconfiguration(/ api,/ ui,…),我只能提供服务。
configuration:
Kibana的configuration:
/opt/kibana/config/kibana.yml
有以下条目:
server.host: "0.0.0.0" server.basePath: "/kibana"
其他一切都是默认的
Doku server.basePath
# Enables you to specify a path to mount Kibana at if you are running behind a proxy. This only affects # the URLs generated by Kibana, your proxy is expected to remove the basePath value before forwarding requests # to Kibana. This setting cannot end in a slash.
nginxconfiguration:
location /kibana/ { rewrite ^/kibana(/.*)$ $1 break; proxy_pass http://<server>.com:5601/; }
我使用sebp / elk:551 docker镜像和下面的docker -compose文件:
version: '2' services: elk: image: sebp/elk:551 container_name: "elk" volumes: - /etc/kibana/config/kibana.yml:/opt/kibana/config/kibana.yml ports: - "5601:5601" - "9200:9200" - "5044:5044" environment: SERVICE_5601_NAME: "kibana" SERVICE_9200_NAME: "elasticsearch" SERVICE_5044_NAME: "logstash" restart: always
我曾经尝试过:
我已经尝试了与Kibana 4.6.1相同的设置,并按预期完美工作。
我testing过的版本不工作:5.4.3,5.1.2,5.0.2
我不想要的:
我不想添加像/api, /ui, /app/kibana, ...
等Kibana的每个子目录/api, /ui, /app/kibana, ...
以添加到代理configuration中。
还有其他解决scheme或版本吗?
编辑1: @ whites11:浏览器从nginx返回502 Bad Gateway站点。 浏览器信息:
一般
Request URL:http://<server-name>.com/kibana/ Request Method:GET Status Code:502 Bad Gateway Remote Address:<server-ip>:80 Referrer Policy:no-referrer-when-downgrade
响应头
Connection:keep-alive Content-Length:575 Content-Type:text/html Date:Thu, 24 Aug 2017 13:54:49 GMT Server:nginx/1.13.3
请求头
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Connection:keep-alive Host:<server-name>.com Upgrade-Insecure-Requests:1
从nginxlogin
34#34: *8 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: <IP>, server: , request: "GET /kibana/ HTTP/1.1", upstream: "http://<server-ip>:5601/", host: "<server-name>.com"
我没有完全相同的部署,但是我使用的是dockerized kibana。
首先,你需要在你的nginx设置中使用以下内容:
location /kibana/ { proxy_pass http://kibana_server:5601/; }
根据您的环境更改值,但最后的斜杠是至关重要的! 不要删除它们! 他们确保重写是按照Kibana所预期的方式完成的–ie, kibana
从去往kibana服务器的请求中的URL中被移除。
然后保持以下内容:
server.basePath: /kibana
在你的kibana设置。 这确保由kibana(链接和URL)提供的文档具有前缀/kibana
。
这个对我有用。
首先,我们无意将Nginx用作反向代理,因此没有必要触及Kibana。 所以沟通你的server.basePath
接下来在下面改变你的nginxconfiguration
location /kibana/ { proxy_pass http://<server>.com:5601/; }
当访问http://<nginxhost>:<port>/kibana/xyz/abc
时,这意味着什么。 这相当于使用http://<server>.com:5601/xyz/abc
。 消除您的系统中的任何复杂性
编辑-1
对于那些认为这不起作用的人来说,情况并非如此。 这是发布此答案之前设置的示例testing用例。
events { worker_connections 1024; } http { server { listen 80; location /test1 { proxy_pass http://127.0.0.1:81; } location /test2 { proxy_pass http://127.0.0.1:81/; } location /test3/ { proxy_pass http://127.0.0.1:81; } location /test4/ { proxy_pass http://127.0.0.1:81/; } } server { listen 81; location / { echo "$request_uri"; } } }
现在结果解释了所有4个位置块之间的区别
$ curl http://192.168.33.100/test1/abc/test /test1/abc/test $ curl http://192.168.33.100/test2/abc/test //abc/test $ curl http://192.168.33.100/test3/abc/test /test3/abc/test $ curl http://192.168.33.100/test4/abc/test /abc/test