K
K
Konstantin Kruglov2016-01-11 17:12:23
Nginx
Konstantin Kruglov, 2016-01-11 17:12:23

How to correctly create location when using proxy_pass?

Hi. I have the following nginx config:

server {
  listen   80;

  # Grafana
  location / {
    add_header Access-Control-Allow-Origin "*";
    proxy_pass http://127.0.0.1:3000/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  # Graphite
  location /graphite/ {
    #add_header Access-Control-Allow-Origin "*";
    proxy_pass http://127.0.0.1:8000/;
    #proxy_set_header Host $host;
    #proxy_set_header X-Real-IP $remote_addr;
    #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

When trying to access 192.168.42.30/graphite , the nginx log shows this
172.16.0.86 - - [11/Jan/2016:17:07:07 +0300] "GET /graphite/ HTTP/1.1" 200 542 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
172.16.0.86 - - [11/Jan/2016:17:07:07 +0300] "GET /browser/header/ HTTP/1.1" 404 1251 "http://192.168.42.30/graphite/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
172.16.0.86 - - [11/Jan/2016:17:07:07 +0300] "GET /composer/? HTTP/1.1" 404 1251 "http://192.168.42.30/graphite/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"

The second and third lines are from Grafana. Tell me how to properly organize location -- graphite?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kruglov, 2016-01-11
@k0st1an

In general, the problem is not so much in nginx, but in the apps themselves. Grafana has a root_url directive : Grafite has
something similar, but it was not possible to build a working version right away. Therefore, I left it as it is and the nginx config looks like this:

server {
  listen   80;

  # Grafana
  location /grafana {
    rewrite  ^/grafana/(.*)  /$1 break;
    proxy_pass http://127.0.0.1:3000;
  }

  # Graphite
  location / { 
    proxy_pass http://127.0.0.1:8000; 
  }
}

Graphite persistently looks for folders in the root of the server, not in the /graphite/ subfolder .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question