Docs: making docs clearer on subpath (#82239)

* making docs clearer on subpath

* Update docs/sources/tutorials/run-grafana-behind-a-proxy/index.md

Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com>

* Update docs/sources/tutorials/run-grafana-behind-a-proxy/index.md

Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com>

* Update docs/sources/tutorials/run-grafana-behind-a-proxy/index.md

Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com>

* Update docs/sources/tutorials/run-grafana-behind-a-proxy/index.md

Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com>

---------

Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com>
This commit is contained in:
Timur Olzhabayev 2024-02-20 14:18:32 +01:00 committed by GitHub
parent 8138ca34a4
commit 1c8a2f136d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,23 +34,9 @@ domain = example.com
- Restart Grafana for the new changes to take effect.
You can also serve Grafana behind a _sub path_, such as `http://example.com/grafana`.
## Configure reverse proxy
To serve Grafana behind a sub path:
1. Include the sub path at the end of the `root_url`.
1. Set `serve_from_sub_path` to `true`. Or, let proxy rewrite the path for you (refer to examples below).
```bash
[server]
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
```
Next, you need to configure your reverse proxy.
## Configure NGINX
### Configure NGINX
[NGINX](https://www.nginx.com) is a high performance load balancer, web server, and reverse proxy.
@ -129,7 +115,7 @@ server {
}
```
If your Grafana configuration does not set `serve_from_sub_path` to true then you need to add a rewrite rule to each location block:
Add a rewrite rule to each location block:
```
rewrite ^/grafana/(.*) /$1 break;
@ -139,7 +125,7 @@ If your Grafana configuration does not set `serve_from_sub_path` to true then yo
If Grafana is being served from behind a NGINX proxy with TLS termination enabled, then the `root_url` should be set accordingly. For example, if Grafana is being served from `https://example.com/grafana` then the `root_url` should be set to `https://example.com/grafana/` or `https://%(domain)s/grafana/` (and the corresponding `domain` should be set to `example.com`) in the `server` section of the Grafana configuration file. The `protocol` setting should be set to `http`, because the TLS handshake is being handled by NGINX.
{{% /admonition %}}
## Configure HAProxy
### Configure HAProxy
To configure HAProxy to serve Grafana under a _sub path_:
@ -150,22 +136,15 @@ frontend http-in
backend grafana_backend
server grafana localhost:3000
```
If your Grafana configuration doesn't set `server.serve_from_sub_path` to `true`, then you must add a rewrite rule to the `backend grafana_backend` block:
```diff
backend grafana_backend
+ # Requires haproxy >= 1.6
+ http-request set-path %[path,regsub(^/grafana/?,/)]
+ # Works for haproxy < 1.6
+ # reqrep ^([^\ ]*\ /)grafana[/]?(.*) \1\2
# Requires haproxy >= 1.6
http-request set-path %[path,regsub(^/grafana/?,/)]
# Works for haproxy < 1.6
# reqrep ^([^\ ]*\ /)grafana[/]?(.*) \1\2
server grafana localhost:3000
```
## Configure IIS
### Configure IIS
> IIS requires that the URL Rewrite module is installed.
@ -192,7 +171,7 @@ This is the rewrite rule that is generated in the `web.config`:
See the [tutorial on IIS URL Rewrites](/tutorials/iis/) for more in-depth instructions.
## Configure Traefik
### Configure Traefik
[Traefik](https://traefik.io/traefik/) Cloud Native Reverse Proxy / Load Balancer / Edge Router
@ -240,6 +219,18 @@ http:
- url: http://192.168.30.10:3000
```
## Summary
## Alternative for serving Grafana under a sub path
In this tutorial you learned how to run Grafana behind a reverse proxy.
**Warning:** You only need this, if you do not handle the sub path serving via your reverse proxy configuration.
If you don't want or can't use the reverse proxy to handle serving Grafana from a _sub path_, you can set the config variable `server_from_sub_path` to `true`.
1. Include the sub path at the end of the `root_url`.
2. Set `serve_from_sub_path` to `true`:
```bash
[server]
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
```