nginx'proxy_pass'不能在位置中包含URI部分吗? [英] nginx 'proxy_pass' cannot have URI part in location?

查看:3255
本文介绍了nginx'proxy_pass'不能在位置中包含URI部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个location

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

但是nginx抱怨"proxy_pass cannot have URI part in location given by regular expression..."有人知道哪里出问题了吗?

我正在尝试在上传完成后查询localhost:5000/1:

location /upload_attachment {
    upload_pass @test;
    upload_store /tmp;
    ...
}

解决方案

从技术上讲,仅添加URI应该可以,因为它是提供了答案,解释了第一种方法为何行不通的原因.

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;
    ...
}

解决方案

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.

这篇关于nginx'proxy_pass'不能在位置中包含URI部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆