From d378240c4bf03e7b5b7d3c95ccaa5f742e49c56a Mon Sep 17 00:00:00 2001 From: Tomasz Napierala Date: Tue, 3 Nov 2020 12:35:21 +0100 Subject: [PATCH] Docs: Add NGINX example for using websockets to Loki (#27998) * feat: added NGINX example for using websockets to Loki * chore: corrections after review * chore: more correrctions from review * chore: creview corrections * chore: addressed review comment by @achatterjee-grafana --- docs/sources/datasources/loki.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/sources/datasources/loki.md b/docs/sources/datasources/loki.md index ad97af98be5..d29189fd7fe 100644 --- a/docs/sources/datasources/loki.md +++ b/docs/sources/datasources/loki.md @@ -134,8 +134,37 @@ Note that Live Tailing relies on two Websocket connections: one between the brow ``` ProxyPassMatch "^/(api/datasources/proxy/\d+/loki/api/v1/tail)" "ws://127.0.0.1:3000/$1" ``` +The following example shows basic NGINX proxy configuration. It assumes that the Grafana server is available at `http://localhost:3000/`, Loki server is running locally without proxy, and your external site uses HTTPS. If you also host Loki behind NGINX proxy, then you might want to repeat the following configuration for Loki as well. -> **Note:** This feature is only available in Grafana v6.3+ +In the `http` section of NGINX configuration, add the following map definition: +``` + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } +``` +In your `server` section, add the following configuration: +``` + location ~ /(api/datasources/proxy/\d+/loki/api/v1/tail) { + proxy_pass http://localhost:3000$request_uri; + 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 "https"; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Upgrade $http_upgrade; + } + + location / { + proxy_pass http://localhost:3000/; + 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 "https"; + } +``` + +> **Note:** This feature is only available in Grafana v6.3+. ## Log Context