H
H
hckn2018-07-29 12:09:33
Nginx
hckn, 2018-07-29 12:09:33

How to set up a proxy without a 301 redirect?

upstream starter_api {
  server 127.0.0.1:7777;
}

location /api/ {
    proxy_pass http://starter_api/;
}

With the current settings location /api/, a request for to http://example.com/apiis redirected to http://example.com/api/. The difference is one lousy slash.
It would seem that everything is simple, remove the slash, but no. If I remove the slash in location /api, then deeper urls stop working, for example http://example.com/api/articles.
How to set it up so that there is no redirect? Why do these slashes require a config?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-07-29
@hckn

location /api/ {
    proxy_pass http://starter_api/;
}
location = /api {
    proxy_pass http://starter_api/;
}

V
Vladimir Mukovoz, 2018-07-29
@castomi

location /api {
    rewrite ^/api(.*)$ /$1 last;
    proxy_pass http://starter_api/;
}

But what you do friend is definitely called a crutch)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question