others-how to put prometheus behind a reverse proxy like nginx?

1. Purpose

In this post, I will demonstrate how to put prometheus server behind a reverse proxy like nginx.



2. Solution

First , start prometheus as follows:

start nginx with external and route :

nohup ./prometheus-2.38.0.linux-amd64/prometheus  --web.external-url=prometheus  --config.file=/opt/prometheus/prometheus.yml > ./nohup.out &

You can refer to this post for the details of the web.external-url.

Then we can configure nginx as follows:

    server {
        listen       80;
        server_name  localhost;
        root         /usr/share/nginx/html;



        location /prometheus/ {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;

                proxy_pass http://127.0.0.1:9090/prometheus/;
        }



3. Summary

In this post, I demonstrated how to put prometheus server behind a nginx. That’s it, thanks for your reading.