Jos*_*ton 17 haproxy http-status-code-404
我目前正在使用 1.5dev-17 重新配置 HAProxy。我想做的是在没有后端用于特定请求时返回 404 错误。
我们当前的配置使用 default_backend 路由到我们的 django 应用服务器,但是当有大量探测请求(如笔测试)与其他配置的后端都不匹配时,我们的 django 服务器在尝试时会停止为这些无效请求提供服务,最终返回 404。
我想从 HAProxy 提供 404,而不是委托给 django 后端。我目前正在通过黑客实现这一目标:
frontend www
...
default_backend nomatch
backend nomatch
errorfile 503 /var/www/http/404.http
Run Code Online (Sandbox Code Playgroud)
在 404.http 文件中,我在标题中设置了 404 状态代码。这有效,但感觉非常错误。使用 HAProxy 有没有更好的方法来实现这一点?或者我应该使用常规后端并让它处理 404 响应?
小智 11
如果您可以接受以下任何响应代码:200、400、403、405、408、429、500、502、503 或 504。
然后你可以做这样的事情:
frontend www
...
default_backend no-match
backend no-match
http-request deny deny_status 400
Run Code Online (Sandbox Code Playgroud)
http-request:http : //cbonte.github.io/haproxy-dconv/1.7/configuration.html#4-http-requesterrorfile:http : //cbonte.github.io/haproxy-dconv/1.7/configuration.html#errorfile| 归档时间: |
|
| 查看次数: |
20321 次 |
| 最近记录: |