您正在查看的是 Apigee Edge 文档。
转到 Apigee X 文档。 信息
在客户端-服务器通信中,如果客户端知道客户端提供的
HTTP 请求方法,但目标资源不支持它,则服务器会返回 HTTP 状态代码 405
Method Not Allowed
。同样,在 Apigee Edge 中,后端服务器可以使用 HTTP 状态代码 405 Method Not Allowed.
进行响应
根据
RFC 7231 第 6.5.5 节:405 不允许的方法,Apigee Edge 要求后端服务器发送 405 Method Not Allowed
响应,其中包含 Allow
标头中允许的方法列表。
Allow
标头必须按以下格式发送:
Allow: HTTP_METHODS
例如,如果您的后端服务器允许使用 GET
、POST
和 HEAD
方法,您需要确保 Allow
标头包含这些方法,如下所示:
Allow: GET, POST, HEAD
如果后端服务器未发送 HTTP 状态代码 405 Method Not Allowed,
的 Allow
标头,则 Apigee 会向客户端应用返回 HTTP 状态代码 502 Bad
Gateway
以及错误代码 protocol.http.Response405WithoutAllowHeader
。如需解决此错误,推荐解决方案是修复后端服务器以遵循规范
RFC 7231,第 6.5.5 节:405 不允许的方法,或使用故障处理返回 HTTP 状态代码 405 Method Not Allowed
(包括 Allow
标头)进行响应,如问题排查手册中所述
502 Bad Gateway - allow Response header 40
不过,在某些特殊情况下,您可能无法立即修复后端或修改 API 代理来解决此问题。
在这种情况下,您可以暂时在消息处理器级别为 405
属性 HTTP.ignore.allow_header.for.405
设置忽略允许标头。将此属性设置为 true
会阻止 Apigee 向客户端应用返回 502 Bad Gateway
响应,即使后端服务器发送的 HTTP 状态代码 405 Method Not Allowed
没有 Allow
标头也是如此。
准备好修复后端服务器以通过 Allow
标头发送 HTTP 状态代码 405 Method
Not Allowed
后,您就可以将属性 HTTP.ignore.allow_header.for.405
还原为默认值 false
。
准备工作
在使用本文档中的步骤之前,请务必了解以下主题:
- 阅读 playbook - 502 Bad Gateway - 响应 405 without allow 标头。
- 如果您不熟悉如何在 Private Cloud 上配置 Edge 的属性,请参阅如何配置 Edge。
在消息处理器上将 405 属性的忽略允许标头配置为 true
在 Apigee Edge 中,属性 HTTP.ignore.allow_header.for.405
默认设置为 false
。这样一来,如果后端服务器发送 HTTP 状态代码 405 Method Not
Allowed
但没有 Allow
标头,Apigee Edge 能够将错误代码为 protocol.http.Response405WithoutAllowHeader
的 502 Bad
Gateway
返回给客户端应用。若要阻止 Apigee Edge 向客户端应用发送 502 Bad Gateway
,您需要在消息处理器上将 HTTP.ignore.allow_header.for.405
属性的值设置为 true
。
本部分介绍了如何按照
如何配置 Edge 中所述的语法使用令牌,在消息处理器上将属性 HTTP.ignore.allow_header.for.405
配置为 true
。
-
在 Message Processor 计算机上,在编辑器中打开以下文件。如果不存在,则创建它。
/opt/apigee/customer/application/message-processor.properties
例如,要使用 vi 打开文件,请输入以下命令:
vi /opt/apigee/customer/application/message-processor.properties
- 按以下格式在属性文件中添加一个代码行:
conf_http_HTTP.ignore.allow_header.for.405=true
- 保存更改。
- 确保属性文件归
apigee
用户所有,如下所示:chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
- 重启消息处理器,如下所示:
/opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
- 如果您有多个消息处理器,请对所有消息处理器重复上述步骤。
在消息处理器上验证 405 属性的忽略允许标头是否设置为 true
本部分介绍了如何验证消息处理器上的 HTTP.ignore.allow_header.for.405
属性是否已成功更新为 true
。
即使您使用令牌 conf_http_HTTP.ignore.allow_header.for.405
更新消息处理器上的属性值,也需要验证实际属性 HTTP.ignore.allow_header.for.405
是否已设置为 true
。
- 在 Message Processor 机器上,在
/opt/apigee/edge-message-processor/conf
目录中搜索HTTP.ignore.allow_header.for.405
属性,检查它是否已设置为true
,如下所示:grep -ri "HTTP.ignore.allow_header.for.405" /opt/apigee/edge-message-processor/conf
- 如果属性在消息处理器上成功更新,则上述命令应在
http.properties
文件中将HTTP.ignore.allow_header.for.405
属性的值显示为true
,如下所示:/opt/apigee/edge-message-processor/conf/http.properties:HTTP.ignore.allow_header.for.405=true
- 如果您仍然看到属性
HTTP.ignore.allow_header.for.405
的值显示为false
,请确认您已正确按照在消息处理器中将 405 属性的忽略允许标头配置为 true 中所述的所有步骤。如果您遗漏了任何步骤,请再次正确重复所有步骤。 - 如果您仍无法修改属性
HTTP.ignore.allow_header.for.405
,请与 Apigee Edge 支持团队联系。
在消息处理器上将 405 属性的忽略 allow 标头配置为 false
本部分介绍了如何按照如何配置 Edge 中所述的语法使用令牌,在消息处理器上将属性 HTTP.ignore.allow_header.for.405
配置为其默认值 false
。
- 验证属性
HTTP.ignore.allow_header.for.405
是否已修改为true
。为此,您可以在/opt/apigee/edge-message-processor/conf
目录中搜索此属性,然后使用以下命令检查其值:grep -ri "HTTP.ignore.allow_header.for.405" /opt/apigee/edge-message-processor/conf
- 如果在消息处理器上将该属性设置为
true
,则上述命令应在http.properties
文件中将HTTP.ignore.allow_header.for.405
属性的值显示为true
,如下所示:/opt/apigee/edge-message-processor/conf/http.properties:HTTP.ignore.allow_header.for.405=true
- 如果上述命令显示
HTTP.ignore.allow_header.for.405
属性已设为false
(默认值),您无需执行任何其他操作。也就是说,跳过以下步骤。 - 如果
HTTP.ignore.allow_header.for.405
属性设为true
,请执行以下步骤以还原为默认值false
。 在 Message Processor 计算机上,使用编辑器打开以下文件:
/opt/apigee/customer/application/message-processor.properties
例如,要使用 vi 打开文件,请输入以下命令:
vi /opt/apigee/customer/application/message-processor.properties
- 从属性文件中移除以下行:
conf_http_HTTP.ignore.allow_header.for.405=true
- 保存更改。
- 确保属性文件归
apigee
用户所有,如下所示:chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
- 重启消息处理器,如下所示:
/opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
- 如果您有多个消息处理器,请对所有消息处理器重复上述步骤。
在消息处理器上,验证 405 属性的忽略允许标头是否设置为 false
本部分介绍了如何验证消息处理器上的 HTTP.ignore.allow_header.for.405
属性是否已成功更新为 false
。
即使您使用令牌 conf_http_HTTP.ignore.allow_header.for.405
更新消息处理器上的值,也需要验证实际属性 HTTP.ignore.allow_header.for.405
是否已设置为 false
。
- 在消息处理器机器上,在
/opt/apigee/edge-message- processor/conf
目录中搜索HTTP.ignore.allow_header.for.405
属性,检查它是否已设置为false
,如下所示:grep -ri "HTTP.ignore.allow_header.for.405" /opt/apigee/edge-message-processor/conf
- 如果属性在消息处理器上成功更新,则上述命令应在
http.properties
文件中将HTTP.ignore.allow_header.for.405
属性的值显示为false
,如下所示:/opt/apigee/edge-message-processor/conf/http.properties:HTTP.ignore.allow_header.for.405=false
- 如果您仍然看到属性
HTTP.ignore.allow_header.for.405
的值显示为true
,请确认您已正确按照 在消息处理器上将 405 属性的忽略允许标头配置为 false 中所述的所有步骤。如果您遗漏了任何步骤,请重新正确重复所有步骤。 - 如果您仍无法修改属性
HTTP.ignore.allow_header.for.405
,请与 Apigee Edge 支持团队联系。