【问题标题】:nginx proxy_pass from a specific path to another specific path throws an errornginx proxy_pass 从特定路径到另一个特定路径会抛出错误
【发布时间】:2018-06-26 23:50:15
【问题描述】:

我反复阅读nginx proxy_pass docs。我以为我理解了它,直到我花了最后一个小时得到一个没有意义的非描述性错误。其他有同样问题的人似乎与此无关。昨天是我使用 nginx 的第一天。我正在运行 nginx v1.12.2。

当有人请求https://example1.com/just-right/search时,我想将该请求代理到https://example2.com/abc.php

location ~ /just-right/search {
    proxy_pass   https://example2.com/abc.php;
}

我得到了错误,而不是代理在 proxy_pass 中定义的路径:

"proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in line .......

我没有使用正则表达式。 “命名位置”是什么意思?它不在 if 语句或“limit_except”块内,我做错了什么?

【问题讨论】:

    标签: nginx nginx-reverse-proxy


    【解决方案1】:

    当您在位置块中使用波浪号 (~) 时,位置将被解释为正则表达式匹配。删除它,它应该可以正确处理。

    在此处查看文档:https://nginx.org/en/docs/http/ngx_http_core_module.html#location

    【讨论】:

    • 谢谢。 location 行是 30,错误指向第 31 行,所以我只看 proxy_pass 行。
    猜你喜欢
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多