仅本地主机上的 Azure Functions 代理 returns 404
Azure Functions proxy returns 404 on localhost only
我遇到的问题似乎与 相同,但解决方案不起作用 - proxies.json 过去和现在都设置为“始终复制”。
我有 .net 核心 API 与 Azure Functions v2 和 docker 容器,我想向其代理一些请求。部署时一切正常,但本地代理 returns 404 响应。
proxies.json
:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"review": {
"debug": true,
"matchCondition": {
"route": "api/{docId}/proxy/review/{*restOfPath}"
},
"backendUri": "https://my-docker-container.azurewebsites.net/{restOfPath}",
"requestOverrides": {
"backend.request.headers.Some-Header": "request.headers.Cookie"
}
}
}
}
本地 docker 容器正在侦听端口 3000,因此我将 backendUri
替换为 http://localhost:3000/{restOfPath}
,但它 returns 404。Docker 端点永远不会打。我可以确认 docker 容器是 运行 并且通过从 Postman 调用 expected URL 来工作。
除了解决方案之外,还有什么方法可以尝试以某种方式更多地调试它吗?无法从日志中获取任何有用信息。
使用已部署资源时的成功日志:
[2021-08-02 10:01:06] Executing HTTP request: {
[2021-08-02 10:01:06] "requestId": "8c60239b-046d-464b-8a3a-09e0f5c55090",
[2021-08-02 10:01:06] "method": "POST",
[2021-08-02 10:01:06] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review"
[2021-08-02 10:01:06] }
[2021-08-02 10:01:06] Function started (Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba)
[2021-08-02 10:01:06] Executing 'Functions.review' (Reason='This function was programmatically called via the host APIs.', Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba)
[2021-08-02 10:01:06] Executing request via Azure Function Proxies
[2021-08-02 10:01:22] Function completed (Success, Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba, Duration=16363ms)
[2021-08-02 10:01:22] Executed 'Functions.review' (Succeeded, Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba)
[2021-08-02 10:01:22] Executed HTTP request: {
[2021-08-02 10:01:22] "requestId": "8c60239b-046d-464b-8a3a-09e0f5c55090",
[2021-08-02 10:01:22] "method": "POST",
[2021-08-02 10:01:22] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review",
[2021-08-02 10:01:22] "authorizationLevel": "Anonymous",
[2021-08-02 10:01:22] "status": "OK"
[2021-08-02 10:01:22] }
使用本地资源的日志不成功:
[2021-08-02 07:58:02] Executing HTTP request: {
[2021-08-02 07:58:02] "requestId": "f562eae9-b2c7-4ef8-84ba-83d42f59c4b7",
[2021-08-02 07:58:02] "method": "POST",
[2021-08-02 07:58:02] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review"
[2021-08-02 07:58:02] }
[2021-08-02 07:58:02] Function started (Id=28149473-125c-4fc4-958d-348604559e10)
[2021-08-02 07:58:02] Executing 'Functions.review' (Reason='This function was programmatically called via the host APIs.', Id=28149473-125c-4fc4-958d-348604559e10)
[2021-08-02 07:58:02] Executing request via Azure Function Proxies
[2021-08-02 07:58:02] Function completed (Success, Id=28149473-125c-4fc4-958d-348604559e10, Duration=169ms)
[2021-08-02 07:58:02] Executed 'Functions.review' (Succeeded, Id=28149473-125c-4fc4-958d-348604559e10)
[2021-08-02 07:58:02] Executed HTTP request: {
[2021-08-02 07:58:02] "requestId": "f562eae9-b2c7-4ef8-84ba-83d42f59c4b7",
[2021-08-02 07:58:02] "method": "POST",
[2021-08-02 07:58:02] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review",
[2021-08-02 07:58:02] "authorizationLevel": "Anonymous",
[2021-08-02 07:58:02] "status": "NotFound"
[2021-08-02 07:58:02] }
更新:
如果有任何疑问,也许 Docker 与它有关,它可以被划掉。创建了新的虚拟机 API,这是同样的问题。
找到解决方案。
感谢 https://markheath.net/post/azure-functions-v2-proxies.
需要在 local.settings.json
中添加 "AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": true
在此之后偶然发现了另一个问题 - backendUri
中的斜杠正在被编码,所以而不是例如http://localhost:3000/api/review
它正在调用 http://localhost:3000/api%2Freview
。同样,只有本地问题。
要解决此问题,需要将 "AZURE_FUNCTION_PROXY_BACKEND_URL_DECODE_SLASHES": true
添加到 local.settings.json
我遇到的问题似乎与
我有 .net 核心 API 与 Azure Functions v2 和 docker 容器,我想向其代理一些请求。部署时一切正常,但本地代理 returns 404 响应。
proxies.json
:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"review": {
"debug": true,
"matchCondition": {
"route": "api/{docId}/proxy/review/{*restOfPath}"
},
"backendUri": "https://my-docker-container.azurewebsites.net/{restOfPath}",
"requestOverrides": {
"backend.request.headers.Some-Header": "request.headers.Cookie"
}
}
}
}
本地 docker 容器正在侦听端口 3000,因此我将 backendUri
替换为 http://localhost:3000/{restOfPath}
,但它 returns 404。Docker 端点永远不会打。我可以确认 docker 容器是 运行 并且通过从 Postman 调用 expected URL 来工作。
除了解决方案之外,还有什么方法可以尝试以某种方式更多地调试它吗?无法从日志中获取任何有用信息。
使用已部署资源时的成功日志:
[2021-08-02 10:01:06] Executing HTTP request: {
[2021-08-02 10:01:06] "requestId": "8c60239b-046d-464b-8a3a-09e0f5c55090",
[2021-08-02 10:01:06] "method": "POST",
[2021-08-02 10:01:06] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review"
[2021-08-02 10:01:06] }
[2021-08-02 10:01:06] Function started (Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba)
[2021-08-02 10:01:06] Executing 'Functions.review' (Reason='This function was programmatically called via the host APIs.', Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba)
[2021-08-02 10:01:06] Executing request via Azure Function Proxies
[2021-08-02 10:01:22] Function completed (Success, Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba, Duration=16363ms)
[2021-08-02 10:01:22] Executed 'Functions.review' (Succeeded, Id=ebfbabc0-1a5b-4129-9280-14ae322e23ba)
[2021-08-02 10:01:22] Executed HTTP request: {
[2021-08-02 10:01:22] "requestId": "8c60239b-046d-464b-8a3a-09e0f5c55090",
[2021-08-02 10:01:22] "method": "POST",
[2021-08-02 10:01:22] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review",
[2021-08-02 10:01:22] "authorizationLevel": "Anonymous",
[2021-08-02 10:01:22] "status": "OK"
[2021-08-02 10:01:22] }
使用本地资源的日志不成功:
[2021-08-02 07:58:02] Executing HTTP request: {
[2021-08-02 07:58:02] "requestId": "f562eae9-b2c7-4ef8-84ba-83d42f59c4b7",
[2021-08-02 07:58:02] "method": "POST",
[2021-08-02 07:58:02] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review"
[2021-08-02 07:58:02] }
[2021-08-02 07:58:02] Function started (Id=28149473-125c-4fc4-958d-348604559e10)
[2021-08-02 07:58:02] Executing 'Functions.review' (Reason='This function was programmatically called via the host APIs.', Id=28149473-125c-4fc4-958d-348604559e10)
[2021-08-02 07:58:02] Executing request via Azure Function Proxies
[2021-08-02 07:58:02] Function completed (Success, Id=28149473-125c-4fc4-958d-348604559e10, Duration=169ms)
[2021-08-02 07:58:02] Executed 'Functions.review' (Succeeded, Id=28149473-125c-4fc4-958d-348604559e10)
[2021-08-02 07:58:02] Executed HTTP request: {
[2021-08-02 07:58:02] "requestId": "f562eae9-b2c7-4ef8-84ba-83d42f59c4b7",
[2021-08-02 07:58:02] "method": "POST",
[2021-08-02 07:58:02] "uri": "/api/4708a861-d8b2-4033-a1da-1a07afca4161/proxy/review/api/review",
[2021-08-02 07:58:02] "authorizationLevel": "Anonymous",
[2021-08-02 07:58:02] "status": "NotFound"
[2021-08-02 07:58:02] }
更新: 如果有任何疑问,也许 Docker 与它有关,它可以被划掉。创建了新的虚拟机 API,这是同样的问题。
找到解决方案。 感谢 https://markheath.net/post/azure-functions-v2-proxies.
需要在 local.settings.json
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": true
在此之后偶然发现了另一个问题 - backendUri
中的斜杠正在被编码,所以而不是例如http://localhost:3000/api/review
它正在调用 http://localhost:3000/api%2Freview
。同样,只有本地问题。
要解决此问题,需要将 "AZURE_FUNCTION_PROXY_BACKEND_URL_DECODE_SLASHES": true
添加到 local.settings.json