nginx不需要的位置redirect与尾部的斜杠

我有一个位置

location /pass/ { proxy_pass http://localhost:12345/; } 

所以它应该代理url http://example.com/pass/whateverhttp://localhost:12345/whatever

我不喜欢的东西是nginx自动添加斜线

 http://example.com/pass 

并通过301redirect使其成为http://example.com/pass/

我怎样才能避免这种行为。 我希望/pass没有斜线去另一个位置。 提前致谢!

这是不可能的,只有你提供的configuration片段。 一个location /pass/ /pass之后永远不会有一个斜线。

而且,你确定你确实想要做你想做的事吗? 如果你要忽略从/pass/pass/的redirect,那么相对path将不起作用。

正如你想要它去另一个位置 ,一个自然的解决办法是添加该位置

 location /pass { } 

默认情况下,nginx将在web根目录中查找一个名为“pass”的文件。 如果你不喜欢这个默认值,你可以在这个新的位置块中添加更多的指令来达到这个目的。

你也可以使用

 location = /pass { } 

这样nginx可以更快地find匹配。