提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
例如:第一章 Python 机器学习入门之pandas的使用
`配置文件
第五章 grafana使用CDN模式进行页面加速
第六章 nginx代理grafana
前言
在上一章中grafana已经使用CDN模式进行了加速,在这里将把grfana放到后端,一切访问都将通过nginx来访问。
提示:以下是本篇文章正文内容,下面案例可供参考
一、在nginx中添加一个虚拟服务器这里使用8081 端口对外进行服务
需要注意的是在nginx中独立配置ws的部分,如果没有配置将会发现如下错误:
1) 在浏览器里可以发现:
2) 在nginx的错误日志中:
server {
listen 8081;
listen [::]:8081;
server_name 192.168.1.122;
access_log /var/log/nginx/host.access.log main;
error_log /var/log/nginx/host.error.log warn;
location / {
add_header Access-Control-Allow-Origin *;
proxy_pass http://192.168.1.120:3000;
proxy_http_version 1.1;
log_not_found off;
proxy_set_header Host $http_host;
#proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 10000;
proxy_read_timeout 10000; #超时配置一定要
}
}
二、对于403 forbidden 错误
需要修改granfa的配置文件
[server] # Protocol (http, https, h2, socket) protocol = http # The ip address to bind to, empty will bind to all interfaces ;http_addr = # The http port to use http_port = 3000 # The public facing domain name used to access grafana from a browser domain = 192.168.1.120 # 这里写入在浏览器中显示的地址 # Redirect to correct domain if host header does not match domain # Prevents DNS rebinding attacks enforce_domain = true # 这里需要从false改成true



