jaks
jaks

Reputation: 4587

nginx on docker doesn't work with location URL

I am running nginx in docker to act as a reverse proxy for multiple applications. for e.g.,

http://localhost/eureka/ will show http://registry:8761
http://localhost/zipkin/ will show http://zipkin:9411

I started with following nginx conf,

http {
  server {

      location /eureka/ {
          proxy_pass http://registry:9761;
      }
  }
}

The above configuration is not working and nginx throwing error as,

proxy       | 172.20.0.1 - - [24/Mar/2017:10:46:28 +0000] "GET /eureka/ HTTP/1.1" 404 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36"

But the below configuration works for http://localhost/ showing eureka page.

http {
  server {

      location / {
          proxy_pass http://registry:9761;
      }
  }
}

What I am missing? As per nginx proxy_pass it should work, but its not.

Upvotes: 1

Views: 3419

Answers (1)

Richard Smith
Richard Smith

Reputation: 49682

The proxy_pass directive can optionally modify the URI before it is passed upstream. To remove the /eureka/ prefix simply append the URI / to the proxy_pass statement.

For example:

location /eureka/ {
    proxy_pass http://registry:9761/;
}

The URI /eureka/foo will be mapped to http://registry:9761/foo. See this document for more.

Of course, this is only half of the problem. In many cases, the upstream application must access its resources using the correct prefix or a path-relative URI. Many applications cannot be forced into a subdirectory.

Upvotes: 3

Related Questions