Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

nginx 'proxy_pass' cannot have URI part in location?

I have a location block as

location @test{
    proxy_pass http://localhost:5000/1;
}

but nginx complains that "proxy_pass cannot have URI part in location given by regular expression..." Does anyone know what might be wrong?

I'm trying to query localhost:5000/1 when an upload is complete:

location /upload_attachment {
    upload_pass @test;
    upload_store /tmp;
    ...
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Technically just adding the URI should work, because it's documented here and it says that it should work, so

location @test{
    proxy_pass http://localhost:5000/1/; # with a trailing slash
}

Should have worked fine, but since you said it didn't I suggested the other way around, the trick is that instead of passing /my/uri to localhost:5000/1, we pass /1/my/uri to localhost:5000,

That's what my rewrite did

rewrite ^ /1$1

Meaning rewrite the whole URL, prepend it with /1 then add the remaining, the whole block becomes

location @test{
    rewrite ^ /1$1;
    proxy_pass http://localhost:5000;
}

Note: @Fleshgrinder provided an answer explaining why the first method didn't work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...