2016-10-21 04:01:34 -05:00
|
|
|
+++
|
|
|
|
title = "Running Grafana behind a reverse proxy"
|
|
|
|
description = "Guide for running Grafana behind a reverse proxy"
|
|
|
|
keywords = ["grafana", "nginx", "documentation", "haproxy", "reverse"]
|
|
|
|
type = "docs"
|
|
|
|
[menu.docs]
|
|
|
|
name = "Running Grafana behind a reverse proxy"
|
|
|
|
parent = "tutorials"
|
|
|
|
weight = 1
|
|
|
|
+++
|
|
|
|
|
2016-09-12 07:47:02 -05:00
|
|
|
|
|
|
|
# Running Grafana behind a reverse proxy
|
|
|
|
|
2016-10-21 04:01:34 -05:00
|
|
|
It should be straight forward to get Grafana up and running behind a reverse proxy. But here are some things that you might run into.
|
2016-09-12 07:47:02 -05:00
|
|
|
|
2016-10-21 04:01:34 -05:00
|
|
|
Links and redirects will not be rendered correctly unless you set the server.domain setting.
|
2017-10-05 12:01:03 -05:00
|
|
|
```bash
|
2016-09-12 07:47:02 -05:00
|
|
|
[server]
|
|
|
|
domain = foo.bar
|
|
|
|
```
|
|
|
|
|
2016-10-21 04:01:34 -05:00
|
|
|
To use sub *path* ex `http://foo.bar/grafana` make sure to include `/grafana` in the end of root_url.
|
|
|
|
Otherwise Grafana will not behave correctly. See example below.
|
2016-09-12 07:47:02 -05:00
|
|
|
|
2017-02-20 05:11:22 -06:00
|
|
|
## Examples
|
2016-09-12 07:47:02 -05:00
|
|
|
Here are some example configurations for running Grafana behind a reverse proxy.
|
|
|
|
|
2018-07-02 11:01:42 -05:00
|
|
|
### Grafana configuration (ex http://foo.bar)
|
2017-02-20 05:11:22 -06:00
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```bash
|
2016-09-12 07:47:02 -05:00
|
|
|
[server]
|
|
|
|
domain = foo.bar
|
|
|
|
```
|
|
|
|
|
2017-02-20 05:11:22 -06:00
|
|
|
### Nginx configuration
|
|
|
|
|
2017-10-05 12:01:03 -05:00
|
|
|
```bash
|
2016-09-12 07:47:02 -05:00
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
root /usr/share/nginx/www;
|
|
|
|
index index.html index.htm;
|
|
|
|
|
|
|
|
location / {
|
|
|
|
proxy_pass http://localhost:3000/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-07-02 11:01:42 -05:00
|
|
|
### Examples with **sub path** (ex http://foo.bar/grafana)
|
2016-09-12 07:47:02 -05:00
|
|
|
|
2017-02-20 05:11:22 -06:00
|
|
|
#### Grafana configuration with sub path
|
2017-10-05 12:01:03 -05:00
|
|
|
```bash
|
2016-09-12 07:47:02 -05:00
|
|
|
[server]
|
|
|
|
domain = foo.bar
|
2018-05-07 07:18:21 -05:00
|
|
|
root_url = %(protocol)s://%(domain)s/grafana/
|
2016-09-12 07:47:02 -05:00
|
|
|
```
|
|
|
|
|
2017-02-20 05:11:22 -06:00
|
|
|
#### Nginx configuration with sub path
|
2017-10-05 12:01:03 -05:00
|
|
|
```bash
|
2016-09-12 07:47:02 -05:00
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
root /usr/share/nginx/www;
|
|
|
|
index index.html index.htm;
|
|
|
|
|
|
|
|
location /grafana/ {
|
|
|
|
proxy_pass http://localhost:3000/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2018-01-23 10:42:53 -06:00
|
|
|
|
|
|
|
#### HAProxy configuration with sub path
|
|
|
|
```bash
|
|
|
|
frontend http-in
|
|
|
|
bind *:80
|
|
|
|
use_backend grafana_backend if { path /grafana } or { path_beg /grafana/ }
|
|
|
|
|
|
|
|
backend grafana_backend
|
|
|
|
# Requires haproxy >= 1.6
|
|
|
|
http-request set-path %[path,regsub(^/grafana/?,/)]
|
|
|
|
|
|
|
|
# Works for haproxy < 1.6
|
|
|
|
# reqrep ^([^\ ]*\ /)grafana[/]?(.*) \1\2
|
|
|
|
|
|
|
|
server grafana localhost:3000
|
|
|
|
```
|
|
|
|
|
2018-01-12 02:41:36 -06:00
|
|
|
### IIS URL Rewrite Rule (Windows) with Subpath
|
|
|
|
|
|
|
|
IIS requires that the URL Rewrite module is installed.
|
|
|
|
|
|
|
|
Given:
|
|
|
|
|
|
|
|
- subpath `grafana`
|
|
|
|
- Grafana installed on `http://localhost:3000`
|
|
|
|
- server config:
|
2018-01-16 02:49:12 -06:00
|
|
|
|
2018-01-12 02:41:36 -06:00
|
|
|
```bash
|
|
|
|
[server]
|
|
|
|
domain = localhost:8080
|
2018-05-07 07:18:21 -05:00
|
|
|
root_url = %(protocol)s://%(domain)s/grafana/
|
2018-01-12 02:41:36 -06:00
|
|
|
```
|
|
|
|
|
2018-01-16 02:49:12 -06:00
|
|
|
Create an Inbound Rule for the parent website (localhost:8080 in this example) in IIS Manager with the following settings:
|
2018-01-12 02:41:36 -06:00
|
|
|
|
|
|
|
- pattern: `grafana(/)?(.*)`
|
|
|
|
- check the `Ignore case` checkbox
|
|
|
|
- rewrite url set to `http://localhost:3000/{R:2}`
|
|
|
|
- check the `Append query string` checkbox
|
|
|
|
- check the `Stop processing of subsequent rules` checkbox
|
|
|
|
|
2018-01-16 02:49:12 -06:00
|
|
|
This is the rewrite rule that is generated in the `web.config`:
|
2018-01-12 02:41:36 -06:00
|
|
|
|
|
|
|
```xml
|
|
|
|
<rewrite>
|
|
|
|
<rules>
|
|
|
|
<rule name="Grafana" enabled="true" stopProcessing="true">
|
|
|
|
<match url="grafana(/)?(.*)" />
|
|
|
|
<action type="Rewrite" url="http://localhost:3000/{R:2}" logRewrittenUrl="false" />
|
|
|
|
</rule>
|
|
|
|
</rules>
|
|
|
|
</rewrite>
|
|
|
|
```
|
2018-01-16 02:49:12 -06:00
|
|
|
|
|
|
|
See the [tutorial on IIS Url Rewrites](http://docs.grafana.org/tutorials/iis/) for more in-depth instructions.
|