nginx - 使用 nginx 重定向特定端点、特定 http 方法
问题描述
我想仅重定向(或 404,等等)一个特定的端点(比如说,/my-path
)和特定的方法(例如POST
)。
我希望其他一切不受影响;也就是说,POST /my-path
将进入 404,但GET /my-path
仍然有效,并且POST /my-path/another-path
也有效。
如何使用 nginx 实现这一点?
解决方案
已解决:使用$request_method
.
示例:使POST
请求接收404
但其他方法可以通过。
location /my-location {
if ($request_method = POST) {
return 404; # or whatever special handling
}
# Normal case goes here
}
推荐阅读
- postgresql - 如何在 Sequelize 的子查询中编写连接?
- spring-boot - 将 Spring Boot 升级到 2.4.2 时 org.springframework.test.context.TestContextAnnotationUtils 上的 ClassNotFoundException
- swift - 如何在 Swift Generic Type 上专门化协议方法?
- angular - 在Angular中更改日期选择器的宽度
- python - 使用密码验证后弹性搜索`无法建立连接,因为目标机器主动拒绝`
- reactjs - 使用 react-intl 在 monorepo 中组合多种语言和源文件
- sql - QuestDB 中的 SQL 通配符匹配列名
- python - 如何从 Python 中的登录响应中提取会话令牌?
- python - 使用 tkinter 在 GUI 框架中嵌入实时控制台
- python - 无法同时使用 Firefox 和 Chrome Webdriver 使用 Python Selenium 触发按钮