2

In image #1, as you can see, I am getting a valid ES response on firing a GET request. However, if I try doing the same things through the NGINX reverse proxy that I have created and hit myip/elasticsearch, it returns me the error (image #2). Can someone help me with this?

server {
    listen 80;
    server_name myip;

    location /elasticsearch/ {
        proxy_pass http://127.0.0.1:9200;
    }
    location /kibana/ {
        proxy_pass http://127.0.0.1:5601;
    }

}

enter image description here

enter image description here

enter image description here

2 Answers 2

2

The right way is to specify both of those slashes. Slash after 127.0.0.1:9000 is essential, without it your request /elasticsearch/some/route would be passed as-is while with that slash it would be passed as /some/route. In nginx terms it means that you specified an URI after the backend name. That is, an URI prefix specified in a location directive (/elasticsearch/) stripped from an original URI (we having some/route at this stage) and an URI specified after the backend name (/) prepended to it resulting in / + some/route = /some/route. You can specify any path in a proxy_pass directive, for example, with proxy_pass http://127.0.0.1:9200/prefix/ that request would be passed to the backend as /prefix/some/route. Now if you understand all being said, you can see that specifying location /elasticsearch { ... } instead of location /elasticsearch/ { ... } would give you //some/route instead of /some/route. I'm not sure it is exactly the cause of your problem however configurations like

    location /elasticsearch/ {
        proxy_pass http://127.0.0.1:9200/;
    }

are more correct.

Now may I ask you what you get with exactly this configuration in response to curl -i http://localhost:9200/ and curl -i http://localhost/? I want to see all the headers (of cause except those containing private information).

Sign up to request clarification or add additional context in comments.

Comments

2

The problem is the path. Nginx is passing it unmodified.

Add a slash at the proxy_pass urls.

server {
    listen 80;
    server_name myip;

    location /elasticsearch/ {
        proxy_pass http://127.0.0.1:9200/;
    }
    location /kibana/ {
        proxy_pass http://127.0.0.1:5601/;
    }

}

From the documentation:

Note that in the first example above, the address of the proxied server is followed by a URI, /link/. If the URI is specified along with the address, it replaces the part of the request URI that matches the location parameter. For example, here the request with the /some/path/page.html URI will be proxied to http://www.example.com/link/page.html. If the address is specified without a URI, or it is not possible to determine the part of URI to be replaced, the full request URI is passed (possibly, modified).

2 Comments

I just realised that there wasn't a need to put an additional slash after the path. Hence, I removed / and now, it looks like location /elasticsearch . However, I keep getting the same exception with proxy_pass http://127.0.0.1:9200/ as well as proxy_pass http://127.0.0.1:9200
It's working now. The slash after port number was important. There was a typo that I made while configuring. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.