skip to Main Content

I am trying to run 2 applications behind an NGINX server.

one is listening on 3000 (grafana) and one is listening on 9090 (prometheus)

My current server block nginx.conf looks like this:

server {
  listen 80;
  root /usr/share/nginx/html;
  index index.html index.htm;

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

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

}

Now for Grafana, this works perfectly and everything works in the dashboard.
But when typing Domain/prometheus it still redirects me to grafana instead of Prometheus.

Do I need todo something specific to have it working in this setup that everything besides /prometheus is redirected to grafana?

2

Answers


  1. Chosen as BEST ANSWER

    So I solved it now by doing this:

    server {
      listen 80;
      root /usr/share/nginx/html;
      index index.html index.htm;
        
    location /prometheus {
       proxy_pass http://localhost:9090/prometheus;
      }
    
       
    location / {
       proxy_pass http://localhost:3000/;
      }
    
    
    }
    

  2. By default, http://localhost:9090 will be redirected to http://localhost:9090/graph, so the request is being redirected as below:

    # the origin request
    http://Domain/prometheus
    
    # the request redirect by nginx
    http://localhost:9090/
    
    # the request redirect by prometheus
    http://Domain/graph
    
    # the request redirect by nginx again
    http://localhost:3000/graph
    
    

    You can check this by using F12 in Chrome.

    To fix this, I recommend you separate the domain into two domains:

    server {
      listen 80;
      server_name Domain-Grafana; # Domain for Grafana
      root /usr/share/nginx/html;
      index index.html index.htm;
    
      location / {
       proxy_pass http://localhost:3000/;
      }
    }
    
    server {
      listen 80;
      server_name Domain-Prometheus; # Domain for Prometheus
      root /usr/share/nginx/html;
      index index.html index.htm;
    
      location / {
       proxy_pass http://localhost:9090/;
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search