nginx 'proxy_pass' 的位置不能有 URI 部分? [英] nginx 'proxy_pass' cannot have URI part in location?
问题描述
我有一个 location
块作为
location @test{
proxy_pass http://localhost:5000/1;
}
但是 nginx 抱怨 proxy_pass 不能在正则表达式给出的位置中包含 URI 部分..."
有谁知道可能出什么问题了?
but nginx complains that "proxy_pass cannot have URI part in location given by regular expression..."
Does anyone know what might be wrong?
我正在尝试在上传完成时查询 localhost:5000/1:
I'm trying to query localhost:5000/1 when an upload is complete:
location /upload_attachment {
upload_pass @test;
upload_store /tmp;
...
}
推荐答案
从技术上讲,只需添加 URI 即可,因为它是 在此处记录 并且它说它应该可以工作,所以
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
}
应该工作得很好,但既然你说没有,我建议相反,诀窍是不要将 /my/uri
传递给 localhost:5000/1
,我们把/1/my/uri
传给localhost:5000
,
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
,
这就是我的重写所做的
rewrite ^ /1$1
意思是重写整个URL,在前面加上/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;
}
注意: @Fleshgrinder 提供了答案 解释了为什么第一种方法不起作用.
Note: @Fleshgrinder provided an answer explaining why the first method didn't work.
这篇关于nginx 'proxy_pass' 的位置不能有 URI 部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!