<ol>
<li><p>You need to add a host entry of <code>mylocalserver</code> in the host file against <code>127.0.0.1</code>, like <code>127.0.0.1 mylocalserver</code>.  </p></li>
<li><p>For <code>/consul</code>, there should be a <code>/consul</code> endpoint in your code to serve your request.</p></li>
</ol>

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

CC BY-SA 3.0
2018-04-11T09:59:26.103Z
location means whatever I  provide that should serve me the request on that location whatever I provide / or /consul (both should work).In both case it should go through this IP 127.0.0.1:8500
Ravat Tailor
CC BY-SA 3.0
2018-04-16T13:35:25.033Z
You are right, with your configuration your all requests will be served but have you configured 'consul' directory in config.json ?   can you show me your consul config file ?
BDShah1994
CC BY-SA 3.0
2018-04-11T08:36:39.027Z
2018-04-13T04:07:57.987Z
2018-04-13T04:07:57.987Z
BDShah1994
<p>I am new to nginx, I have configured my consul with nginx.</p>

<p>It's working but I have few doubts in my configuration.</p>

<p>here is my configuration  </p>

<pre><code>upstream consul {
  server 127.0.0.1:8500;
} 

server {
  listen 80 default_server;
  server_name localhost;

  location / {
    proxy_pass http://consul;
  }
}
</code></pre>

<p>this is working fine if hit <a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>, in my machine I am able to see consul UI.</p>

<p>But If I change my location to <strong>/consul</strong>, it is giving 404.</p>

<p>and what is the use of server name, if I change it to <strong>server_name mylocalserver;</strong></p>

<p>I think I should be able to run my gttp request on this address <a href="http://mylocalserver" rel="nofollow noreferrer">http://mylocalserver</a>. but that is also not working.</p>

CC BY-SA 3.0
2018-04-16T10:00:09.003Z
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
<nginx>
use of nginx server_name
Ravat Tailor
# use of nginx server_name

(Asked by: username_0 on 2018-04-11)

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.

**Tags:** nginx

> **Comments:**
> **username_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.  

---

## 1 answers

### Answer by username_2 on 2018-04-11. Score: 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.

> **Comments:**
> **username_0**: location means whatever I  provide that should serve me the request on that location whatever I provide / or /consul (both should work).In both case it should go through this IP 127.0.0.1:8500  
> **username_2**: You are right, with your configuration your all requests will be served but have you configured 'consul' directory in config.json ?   can you show me your consul config file ?  

---

