[转帖]Run Grafana behind a reverse proxy
Newsletter
Want to stay on top of Grafana and Observability news? Sign up for our newsletter.
By Grafana Labs Team
Last update on July 18, 2023
Introduction
In this tutorial, you’ll configure Grafana to run behind a reverse proxy.
When running Grafana behind a proxy, you need to configure the domain name to let Grafana know how to render links and redirects correctly.
- In the Grafana configuration file, change
server.domainto the domain name you’ll be using:
[server]
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.
To serve Grafana behind a sub path:
- Include the sub path at the end of the
root_url. - Set
serve_from_sub_pathtotrue.
[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
NGINX is a high performance load balancer, web server, and reverse proxy.
- In your NGINX configuration file inside
httpsection, add the following:
# this is required to proxy Grafana Live WebSocket connections.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream grafana {
server localhost:3000;
}
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
# Proxy Grafana Live WebSocket connections.
location /api/live/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
}
- Reload the NGINX configuration.
- Navigate to port 80 on the machine NGINX is running on. You’re greeted by the Grafana login page.
For Grafana Live which uses WebSocket connections you may have to raise Nginx worker_connections option which is 512 by default – which limits the number of possible concurrent connections with Grafana Live.
Also, be aware that the above configuration will work only when the proxy_pass value for location / is a literal string. If you are using a variable here, read this GitHub issue. You will need to add an appropriate NGINX rewrite rule.
To configure NGINX to serve Grafana under a sub path, update the location block:
# this is required to proxy Grafana Live WebSocket connections.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream grafana {
server localhost:3000;
}
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm;
location /grafana/ {
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
# Proxy Grafana Live WebSocket connections.
location /grafana/api/live/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
}
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:
rewrite ^/grafana/(.*) /$1 break;
Note: If Grafana is being served from behind a NGINX proxy with TLS termination enabled, then the
root_urlshould be set accordingly. For example, if Grafana is being served fromhttps://example.com/grafanathen theroot_urlshould be set tohttps://example.com/grafana/orhttps://%(domain)s/grafana/(and the correspondingdomainshould be set toexample.com) in theserversection of the Grafana configuration file. Theprotocolsetting should be set tohttp, because the TLS handshake is being handled by NGINX.
Configure HAProxy
To configure HAProxy to serve Grafana under a sub path:
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
Configure IIS
IIS requires that the URL Rewrite module is installed.
To configure IIS to serve Grafana under a sub path, create an Inbound Rule for the parent website in IIS Manager with the following settings:
- pattern:
grafana(/)?(.*) - check the
Ignore casecheckbox - rewrite URL set to
http://localhost:3000/{R:2} - check the
Append query stringcheckbox - check the
Stop processing of subsequent rulescheckbox
This is the rewrite rule that is generated in the web.config:
<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>
See the tutorial on IIS URL Rewrites for more in-depth instructions.
Configure Traefik
Traefik Cloud Native Reverse Proxy / Load Balancer / Edge Router
Using the docker provider the following labels will configure the router and service for a domain or subdomain routing.
labels:
traefik.http.routers.grafana.rule: Host(`grafana.example.com`)
traefik.http.services.grafana.loadbalancer.server.port: 3000
To deploy on a sub path
labels:
traefik.http.routers.grafana.rule: Host(`example.com`) && PathPrefix(`/grafana`)
traefik.http.services.grafana.loadbalancer.server.port: 3000
Examples using the file provider.
http:
routers:
grafana:
rule: Host(`grafana.example.com`)
service: grafana
services:
grafana:
loadBalancer:
servers:
- url: http://192.168.30.10:3000
http:
routers:
grafana:
rule: Host(`example.com`) && PathPrefix(`/grafana`)
service: grafana
services:
grafana:
loadBalancer:
servers:
- url: http://192.168.30.10:3000
Summary
In this tutorial you learned how to run Grafana behind a reverse proxy.
[转帖]Run Grafana behind a reverse proxy的更多相关文章
- Nginx应用-Location路由反向代理及重写策略 请求转发-URL匹配规则 NGINX Reverse Proxy
NGINX Docs | NGINX Reverse Proxy https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ ...
- Master Nginx(5) - Reverse Proxy Advanced Topics
Security through separtion Encrypting traffic with SSL Authenticating clients using SSL Blocking tra ...
- Forward Proxy & Reverse Proxy | 正向代理 和 反向代理
对请求和响应内容不做修改的转发的服务器,被称为代理服务器.代理服务器分为两种类型:正向代理 和 反向代理. 正向代理:面向互联网,从更广范围获取信息的代理. 反向代理:面向内部,一般用于某企业的网站的 ...
- 反向代理(Reverse Proxy)
反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时 ...
- 正向代理 forward proxy、反向代理 reverse proxy、透明代理 transparent proxy nginx反向代理原理和配置讲解 防止外部客户机获取内部内容服务器的重定向 URL 缓存命中
[大型网站技术实践]初级篇:借助Nginx搭建反向代理服务器 - Edison Chou - 博客园http://www.cnblogs.com/edisonchou/p/4126742.html 图 ...
- Differences Between 3 Types Of Proxy Servers: Normal, Transparent And Reverse Proxy
What is a Proxy Server? A Proxy server is an intermediary machine, between a client and the actual s ...
- Forward Proxy vs Reverse Proxy
Overview We've talked about reverse proxy servers and how they can really be good at protecting the ...
- an open source web server and reverse proxy
https://www.nginx.com/resources/admin-guide/ NGINX is an open source web server and reverse proxy th ...
- Nginx & Reverse Proxy
Nginx & Reverse Proxy https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ https:/ ...
- 反向代理服务器(Reverse Proxy)
反向代理服务器(Reverse Proxy) 普通代理服务器是帮助内部网络的计算机访问外部网络.通常,代理服务器同时连接内网和外网.首先内网的计算机需要设置代理服务器地址和端口,然后将HTTP请求 ...
随机推荐
- 机器学习周刊03:如何学习深度学习?2024 年学习生成式 AI 路线图、如何构建高效的RAG系统、苹果 腾讯最新论文、阿里DreaMoving
腾讯推出的 AppAgent,是一个多模态智能体,通过识别当前手机的界面和用户指令直接操作手机界面,能像真实用户一样操作手机! 机器学习周刊:关注Python.机器学习.深度学习.大模型等硬核技术 1 ...
- 【scikit-learn基础】--『监督学习』之 均值聚类
聚类算法属于无监督学习,其中最常见的是均值聚类,scikit-learn中,有两种常用的均值聚类算法:一种是有名的K-means(也就是K-均值)聚类算法,这个算法几乎是学习聚类必会提到的算法:另一个 ...
- js-audio-pluging(录音)
安装 npm i js-audio-recorder 代码 <template> <div class="BaseRecorder"> <div cl ...
- 手把手带你写Node.JS版本小游戏
摘要:今天就利用Node.JS为大家带来简单有趣的的剪刀石头布的小游戏. JavaScript的出现催动了前端开发的萌芽,前后端分离促进了Vue.React等开发框架的发展,Weex.React-Na ...
- 华为云张昆:支持全场景全业务,GaussDB加速企业数字化转型
云.AI.5G等技术驱动,数据库行业迎来新的需求,云数据库也在不断演进升级.依托华为云与华为云Stack,通过全栈软硬件优化,华为云GaussDB进行了进阶与革新,以统一的架构,支持关系型与非关系型的 ...
- makefile:带你了解一种常用于GNU gcc编译的工具语言
摘要:该文章主要介绍makefile,一种常用语GNU gcc编译的工具语言,同时LiteOS也是利用该文件对工程项目进行make构建生成执行文件的. LiteOS源码中使用makefile进行文件的 ...
- 云小课|云小课带您快速了解LTS可视化查看
阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要: 可视化查看是日志 ...
- CodeLab:一款让你体验丝滑般的云化JupyterLab
摘要:从AI开发特点着手,华为云AI DTSE技术布道师陈阳在DTT第五期带来主题为<云化JupyterLab:华为云CodeLab介绍>技术分享. DTSE Tech Talk是华为云开 ...
- 华为云企业级Redis:助力VMALL打造先进特征平台
摘要:当电商平台对AI算法模型的需求越来越多,特征数据平台的统一建设是不少开发团队头疼的事情.因为只有通过统一的特征数据存储,才能改变原有的"数据孤岛",解决生产重复造轮子的窘境. ...
- MAC SAP for JAVA配置
一.自定义应用程序服务器配置 conn = /H/<SAP路由器服务器地址(如果有)>/S/3299 /H/<SAP服务器地址>/S/32<Instance_no> ...