【问题标题】:Redirect specific endpoint, specific http method with nginx使用 nginx 重定向特定端点、特定 http 方法
【发布时间】:2021-06-10 11:03:33
【问题描述】:

我只想重定向(或 404 等)特定端点(例如,/my-path)和特定方法(例如 POST)。
我希望其他一切不受影响;也就是说,POST /my-path 将变为 404,但 GET /my-path 仍然有效,POST /my-path/another-path 也有效。

如何使用 nginx 实现这一点?

【问题讨论】:

    标签: nginx


    【解决方案1】:

    已解决:使用$request_method

    示例:使POST 请求接收404 但其他方法可以通过。

    location /my-location {
        if ($request_method = POST) {
            return 404;  # or whatever special handling
        }
        # Normal case goes here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-25
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      相关资源
      最近更新 更多