HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

use of nginx server_name

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
useserver_namenginx

Problem

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.

Solution

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

-
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.

Context

StackExchange DevOps Q#3856, answer score: 1

Revisions (0)

No revisions yet.