【问题标题】:Remove query string in Nginx proxy_pass删除 Nginx proxy_pass 中的查询字符串
【发布时间】:2015-09-21 14:39:29
【问题描述】:

是否可以在 Nginx 中使用 proxy_pass 删除查询字符串? 例如,我将我的 nginx 称为:

http://nginxproxy.com/api/v1/logout?session=123

并希望将其代理到:

http://example.com/api/sessions/?_action=logout

没有查询字符串“session=123”。

目前我的设置只是将我传递给 proxy_pass URL 的任何查询字符串添加。

location /api/v2/logout {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Session $arg_token;
        proxy_pass http://example.com/api/sessions/?_action=logout;
}

【问题讨论】:

  • 你发现了吗?

标签: nginx


【解决方案1】:

如果您要删除在 /api/v2/logout 上指定的任何查询字符串,添加 set $args ""; 应该可以:

location /api/v2/logout {
    set $args "";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Session $arg_token;
    proxy_pass http://example.com/api/sessions/?_action=logout;
}

【讨论】:

    【解决方案2】:

    我相信您可以使用以下重写规则来做到这一点:

    rewrite ^(.*)$ $1?;
    

    【讨论】:

      猜你喜欢
      • 2013-06-27
      • 2018-03-15
      • 2016-10-25
      • 2020-11-13
      • 2011-12-29
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多