2017-08-26 96 views
1

我們有一個dockerized架構。唯一的主要入口是我們的nginx。這使得我們所有的服務之間的聯繫。Nginx位置/日誌不能正確傳遞給Kibana,導致404

到達位置/的域名正常工作。我們的Angular前端應用程序正確顯示。

主要問題是訪問/logs位置上的KIBANA(v5.5)。

例如,試圖達到https://dev.example.com/logs/瀏覽器顯示404,因爲它試圖達到https://dev.example.com/login?next=%2Flogs

看起來像我們位置端點中的代理Kibana試圖重寫url的基址爲/。而不是在/ logs/location之後重寫URI。

如何將我們的配置改進爲: - 允許到達/ logs /,它能正確顯示我們的Kibana應用程序?

這是我們的nginx配置。請注意,客戶端,後端,kibana是指碼頭主機名。捲曲請求

server { 
    listen 443; 
    ssl  on; 
    rdns on; 

    ssl_certificate /etc/ssl/production/certs/example/fullchain.pem; 
    ssl_certificate_key /etc/ssl/production/certs/example/privkey.pem; 

    server_name dev.example.com; 

    # Angular APP 
    location/{ 
     proxy_pass http://client; 
     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; 
    } 

    # Backend proxy 
    location /api { 
     proxy_pass http://backend:9090; 
     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; 
    } 

    # Logs on Kibana 
    location /logs { 
     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; 
    } 
} 

結果:

curl -v https://dev.example.com/logs/ 
* About to connect() to dev.example.com port 443 (#0) 
* Trying xx.xx.xx.xx... 
* connected 
* Connected to dev.example.com (xx.xx.xx.xx) port 443 (#0) 
* SSLv3, TLS handshake, Client hello (1): 
* SSLv3, TLS handshake, Server hello (2): 
* SSLv3, TLS handshake, CERT (11): 
* SSLv3, TLS handshake, Server key exchange (12): 
* SSLv3, TLS handshake, Server finished (14): 
* SSLv3, TLS handshake, Client key exchange (16): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSL connection using ECDHE-RSA-AES256-GCM-SHA384 
* Server certificate: 
*  subject: CN=example.com 
*  start date: 2017-08-23 17:26:00 GMT 
*  expire date: 2017-11-21 17:26:00 GMT 
*  subjectAltName: dev.example.com matched 
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3 
*  SSL certificate verify ok. 
> GET /logs HTTP/1.1 
> User-Agent: curl/7.28.1 
> Host: dev.example.com 
> Accept: */* 
> 
< HTTP/1.1 404 Not Found 
< Server: nginx/1.13.1 
< Date: Sat, 26 Aug 2017 15:39:43 GMT 
< Content-Type: text/html 
< Content-Length: 169 
< Connection: keep-alive 
< 
<html> 
<head><title>404 Not Found</title></head> 
<body bgcolor="white"> 
<center><h1>404 Not Found</h1></center> 
<hr><center>nginx/1.13.1</center> 
</body> 
</html> 
* Connection #0 to host dev.example.com left intact 
* Closing connection #0 
* SSLv3, TLS alert, Client hello (1): 

非常感謝您對這個幫助。

+0

在哪個端口上您的客戶端應用程序上運行? –

+0

它運行在'80'上 – BlackHoleGalaxy

+0

'/ logs'應該去kibana,即使它出錯了。這有些不對勁。你可以將'curl -v http:// nginxip/logs'的結果添加到你的問題中,這樣你就可以看到發生了什麼。此外,nginx容器日誌與去那將是最好的 –

回答

1

您需要將server.basePath設置爲/logs,方法是將SERVER_BASEPATH環境變量傳遞給kibana容器。

然後,你需要在代理位置使用重寫剝去/日誌前綴nginx的:

location /logs { 
    rewrite ^/logs(/.*)$ $1 break; 
    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; 
} 

再加上,顯然是在kibana一個bug,和上面的配置工作,只有當我們到達kibana與以下網址:

http://nginxip/logs/ 

但如果我們沒有結束斜線,如:

http://nginxip/logs 

爲了解決這個問題,我們需要在nginx中添加另一個重寫,以確保始終有一個結束斜線。添加/日誌位置以下之外:

rewrite ^/logs$ /logs/; 

來源:https://www.elastic.co/guide/en/kibana/current/settings.html

+0

感謝您的幫助。這裏是我結束的地方:'location/logs/{ \t \t rewrite ^/logs(/。*)最後$ 1美元; \t \t proxy_pass http:// kibana:5601; \t \t proxy_set_header Host $ host; \t \t proxy_set_header X-Real-IP $ remote_addr; \t \t proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; \t \t proxy_set_header X-Forwarded-Proto $ scheme; \t}'但達到/日誌/讓我落在客戶端(通過/達到) – BlackHoleGalaxy

+0

好吧,我嘗試了整個安裝在我的機器上,並調整了我的答案。希望它也適用於你 – whites11

+0

感謝休息而不是最終的作品!謝謝你的幫助。 – BlackHoleGalaxy