1.nginx 設置
server { listen 127.0.0.1:80; #server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; # proxy_pass http://127.0.0.1:9090/; } location /grafana/ { proxy_pass http://10.xx.xxx.55:3000/; } location /prometheus/ { proxy_pass http://10.xx.xxx.55:9090/prometheus/; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
2.設置prometheus子路徑
接下來需要的是將prometheus和grafana在啟動或者配置文件中做一些更改,prometheus的相對來說比較簡單,主要實在啟動的時候根據命令行的參數來進行子路徑設置。
在啟動的時候設置web.external-url
使用下面的命令:
./prometheus --web.external-url=prometheus --config.file=prometheus.yml
啟動服務,結果如圖:
3.設置grafana子路徑
grafana的代理需要在default.ini
中配置
# The full public facing url root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
重啟服務,結果如圖: