您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。 info
在用戶端與伺服器通訊中,如果伺服器知道用戶端提供的
HTTP 要求方法,但目標資源不支援該方法,伺服器會傳回 HTTP 狀態碼 405
Method Not Allowed。同樣地,在 Apigee Edge 中,後端伺服器可以傳回 HTTP 狀態碼 405 Method Not Allowed.
根據規格
RFC 7231 第 6.5.5 節:405 Method Not Allowed,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 Method Not Allowed,或使用錯誤處理機制,以 HTTP 狀態碼 405 Method Not Allowed (包括 Allow 標頭) 回應,如疑難排解手冊「
502 Bad Gateway - Response 405 without Allow header」一文所述。
不過,在某些特殊情況下,您可能無法立即修正後端或修改 API Proxy 來解決這個問題。
在這種情況下,您可以暫時在訊息處理器 層級,為 405 屬性設定忽略允許標頭。HTTP.ignore.allow_header.for.405將這項屬性設為 true,可防止 Apigee 將 502 Bad Gateway 回應傳回用戶端應用程式,即使後端伺服器傳送的 HTTP 狀態碼為 405 Method Not Allowed,且不含 Allow 標頭也一樣。
修正後端伺服器,使其傳送 HTTP 狀態碼 405 Method
Not Allowed 和 Allow 標頭後,即可將屬性 HTTP.ignore.allow_header.for.405 還原為預設值 false。
事前準備
使用本文中的步驟前,請務必瞭解下列主題:
- 閱讀應對手冊 - 502 Bad Gateway - response 405 without Allow header。
- 如果您不熟悉如何為 Private Cloud 上的 Edge 設定屬性,請參閱「如何設定 Edge」。
在訊息處理器上,將 405 屬性的「忽略允許標頭」設為 true
在 Apigee Edge 中,屬性 HTTP.ignore.allow_header.for.405 預設設為 false。如果後端伺服器傳送 HTTP 狀態碼 405 Method Not
Allowed,但沒有 Allow 標頭,Apigee Edge 就能傳回 502 Bad
Gateway 和錯誤碼 protocol.http.Response405WithoutAllowHeader 給用戶端應用程式。如要防止 Apigee Edge 將 502 Bad Gateway 傳送至用戶端應用程式,請將 HTTP.ignore.allow_header.for.405 屬性的值設為「Message Processors」上的 true。
本節說明如何使用權杖,按照「
如何設定 Edge」一文所述的語法,在 Message Processor 上將 HTTP.ignore.allow_header.for.405 屬性設定為 true。
-
在訊息處理器電腦上,使用編輯器開啟下列檔案。如果該目錄不存在,請建立該目錄。
/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
本節說明如何確認資源已成功更新至 Message Processors 上的 HTTP.ignore.allow_header.for.405true。
即使您使用權杖 conf_http_HTTP.ignore.allow_header.for.405 更新訊息處理器上的屬性值,仍須驗證實際屬性 HTTP.ignore.allow_header.for.405 是否已設為 true。
- 在訊息處理器電腦上,搜尋
/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,請確認您已正確按照「在 Message Processors 中將 405 屬性的 ignore allow 標頭設為 true」一文中的所有步驟操作。如果遺漏任何步驟,請再次正確執行所有步驟。 - 如果還是無法修改屬性
HTTP.ignore.allow_header.for.405,請與 Apigee Edge 支援團隊聯絡。
在訊息處理器上,將 405 屬性的「忽略允許標頭」設為 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。 在訊息處理器電腦上,使用編輯器開啟下列檔案:
/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.405false。
即使您使用權杖 conf_http_HTTP.ignore.allow_header.for.405 更新 Message Processor 的值,仍須確認實際屬性 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,請確認您已正確按照「 在 Message Processors 上將 405 資源的忽略允許標頭設為 false」一文中的所有步驟操作。如果遺漏任何步驟,請再次正確執行所有步驟。 - 如果還是無法修改屬性
HTTP.ignore.allow_header.for.405,請與 Apigee Edge 支援團隊聯絡。