【问题标题】:Nginx removing second slash in location blockNginx 删除位置块中的第二个斜杠
【发布时间】:2013-12-13 18:27:46
【问题描述】:

当访问一个唯一的 URL 时,我正在尝试使用 proxy_pass 设置 nginx:

location ~ /proxy/(?<var>.+) {
    proxy_pass $var;
}

当我访问http://example.com/proxy/http://google.com 时,我收到 500 Internal Server Error,错误日志有以下条目:

“http:/google.com”中的 URL 前缀无效,客户端:2.33.214.165, 服务器:example.com,请求:“GET /proxy/http://google.com HTTP/1.1”, 主机:“example.com”

有什么原因导致 nginx 在 URL 中不包含第二个/

【问题讨论】:

    标签: nginx


    【解决方案1】:

    试试这个:merge_slashes 尽管上下文是服务器范围的,所以如果您仍然需要在其他地方合并斜杠,则必须在将代理目标拆分为模式和主机 + uri 的位置改进正则表达式。像这样:^/proxy/(?&lt;schema&gt;.+)://(?&lt;rest&gt;) 然后proxy_pass $schema://$rest 可能会起作用。

    【讨论】:

      猜你喜欢
      • 2016-04-21
      • 1970-01-01
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多