S
S
Sergey Goryachev2020-01-24 15:06:00
Nginx
Sergey Goryachev, 2020-01-24 15:06:00

How to compose location for proxy_pass with regular expression?

I need to proxy all requests like host/some/server/ to another ip.
some can be anything.
There can be both get with arguments and POST with a body.
The problem is that when I do this

location ^~/some/server/ {
  proxy_pass http://192.168.81.71;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
}

everything is running fine. But some is written explicitly, which does not suit me.
At
location ~^/(some1|some2)/server/(.*) {
  proxy_pass http://000.000.000.000/$1/server/$2?$args;

Only GET with arguments goes. And even GET to php does not go.
In fact, I need everything that has a server in the second uri segment to be proxied to another host.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Goryachev, 2020-01-24
@SergeGoryachev

Actually, the problem was resolved in a banal way.
location ~^/(.*)/server/ {
proxy_pass http://host;
Worked great.
The problem was ok location.
I moved it to the beginning of the config and everything worked.
Thanks

V
Vadim Priluzkiy, 2020-01-24
@Oxyd

Do you have a bug? In a working config Versus In that where does not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question