Categories
Uncategorized

Reverse proxy with nginx and Prometheus on Centos 7

After installing ngxinx using yum install, create a prometheus config

touch /etc/nginx/conf.d/prometheus.conf
emacs /etc/nginx/conf.d/prometheus.conf

Add the following to prometheus.conf

server {
       listen 80;
       listen [::]:80;
       server_name      prometheus.local;

       location / {
                proxy_pass      http://localhost:9090/;
       }
}

Restart nginx, now you should be able to access http://prometheus.local

Add HTTPS support

The cert was done with mkcert and the files moved to a directory in /etc/nginx/mkcerts. Change the port to 9090 to load the prometheus site, port 3000 points to grafana.

server {
       listen 80;
       listen 443 ssl;

       ssl_certificate /etc/nginx/mkcerts/prometheus2.local.pem;
       ssl_certificate_key /etc/nginx/mkcerts/prometheus2.local-key.pem;

       server_name      prometheus2.local;
       location / {
                proxy_pass      http://localhost:3000/;
       }

}

Add Basic Authentication to prometheus

First install

yum install httpd-tools

Now create the password

htpasswd -c /etc/nginx/.htpasswd username

Now modify /etc/nginx/conf.d/prometheus.conf

server {
       listen 80;
       listen 443 ssl;

       ssl_certificate /etc/nginx/mkcerts/prometheus2.local.pem;
       ssl_certificate_key /etc/nginx/mkcerts/prometheus2.local-key.pem;

       auth_basic  "Protected Area";
       auth_basic_user_file /etc/nginx/.htpasswd;

       server_name      prometheus2.local;
       location / {
                proxy_pass      http://localhost:9090/;
       }

}

Restart prometheus