3

I am new to nginx, I have configured my consul with nginx.

It's working but I have few doubts in my configuration.

here is my configuration

upstream consul {
  server 127.0.0.1:8500;
} 

server {
  listen 80 default_server;
  server_name localhost;

  location / {
    proxy_pass http://consul;
  }
}

this is working fine if hit http://localhost, in my machine I am able to see consul UI.

But If I change my location to /consul, it is giving 404.

and what is the use of server name, if I change it to server_name mylocalserver;

I think I should be able to run my gttp request on this address http://mylocalserver. but that is also not working.

Ravat Tailor
  • 153
  • 6
  • 1
    if you change your location to /consul, it does pass /consul to the backend also, which consul has no clue about unless you did configure it for that endpoint. – Tensibai Apr 16 '18 at 10:00

1 Answers1

1
  1. You need to add a host entry of mylocalserver in the host file against 127.0.0.1, like 127.0.0.1 mylocalserver.

  2. For /consul, there should be a /consul endpoint in your code to serve your request.

As per your configuration, your http://localhost will be served because you have set proxypass for "/"(all). It will send all requests to the application/server and will be served.

Rekovni
  • 933
  • 10
  • 24
BDShah1994
  • 11
  • 1