Home > Mobile >  Nginx proxy_pass hierarchy
Nginx proxy_pass hierarchy

Time:04-12

I'm running nginx in docker with a asp.net web-service. If I write my conf like this, I can't get to e.g. http://localhost/order-service/api
This results in "The resource you have requested cannot be found".
The /hubs endpoint is working.

upstream order-service {
    server order-service:5048;
}

# HTTP
server {
    listen        80;

    location = /order-service/hubs {
        proxy_pass http://order-service/hubs;
        ...
    }

    location /order-service {
        proxy_pass http://order-service;
        ...
    }
}

If I change it to:

upstream order-service {
    server order-service:5048;
}

# HTTP
server {
    listen        80;

    location = /order-service/hubs {
        proxy_pass http://order-service/hubs;
        ...
    }

    location /order-service/api {        <--- here is the change!!!
        proxy_pass http://order-service;
        ...
    }
}

I can get the api with http:/localhost/order-service

But I have other urls like order-service/ui and order-service/settings. What must I use to lead all request to order-service but order-service/hubs?

CodePudding user response:

The two expressions:

location /order-service/ {
    proxy_pass http://order-service;
}

And:

location /order-service/ {
    proxy_pass http://order-service/;
}

will generate totally different results.

In the first case, the request /order-service/api will be proxied upstream as:

http://order-service/order-service/api

In the second case, the same request will be translated into:

http://order-service/api

Looking at your location = /order-service/hubs block, you probably need the second case.

See this document for details.

  • Related