Search code examples
nginxserverreverse-proxyprometheusgrafana

multiple location blocks in nginx and proxy pass


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?


Solution

  • 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/;
      }
    
    
    }