【发布时间】:2019-03-28 22:48:20
【问题描述】:
错误
在部署到支持多容器的 Azure Web 应用时,我收到来自https://mysite.azurewebsites.com
的“Invalid Host Header” 消息本地设置
运行良好。
我有两个 Docker 容器:client 一个 React 应用和 server 一个托管我的 API 的 Express 应用。我正在使用代理在 server 上托管我的 API。
在client的package.json中我定义了:
"proxy": "http://localhost:3001"
我使用以下 docker compose 文件在本地构建。
version: '2.1'
services:
server:
build: ./server
expose:
- ${APP_SERVER_PORT}
environment:
API_HOST: ${API_HOST}
APP_SERVER_PORT: ${APP_SERVER_PORT}
ports:
- ${APP_SERVER_PORT}:${APP_SERVER_PORT}
volumes:
- ./server/src:/app/project-server/src
command: npm start
client:
build: ./client
environment:
- REACT_APP_PORT=${REACT_APP_PORT}
expose:
- ${REACT_APP_PORT}
ports:
- ${REACT_APP_PORT}:${REACT_APP_PORT}
volumes:
- ./client/src:/app/project-client/src
- ./client/public:/app/project-client/public
links:
- server
command: npm start
一切正常。
在 Azure 上
部署到 Azure 时,我有以下内容。 client 和 server 图像已存储在 Azure 容器注册表中。它们似乎从日志中加载得很好。
在我的应用服务 > 容器设置中,我正在从 Azure 容器注册表 (ACR) 加载图像,并且正在使用以下配置(Docker compose)文件。
version: '2.1'
services:
client:
image: <clientimage>.azurecr.io/clientimage:v1
build: ./client
expose:
- 3000
ports:
- 3000:3000
command: npm start
server:
image: <serverimage>.azurecr.io/<serverimage>:v1
build: ./server
expose:
- 3001
ports:
- 3001:3001
command: npm start
我也在应用程序设置中定义了:
WEBSITES_PORT 为 3000。
这会导致我的网站出现错误“Invalid Host Header”
我尝试过的事情
• 从server 中的static 文件夹提供应用程序。这有效,因为它为应用程序提供服务,但它弄乱了我的身份验证。我需要能够提供来自client 的 App.js 的静态部分,并与我的 Express API 对话以进行数据库调用和身份验证。
• 在我的 docker-compose 文件中将前端绑定到:
ports:
- 3000:80
• 其他一些端口组合,但没有运气。
另外,我认为这与基于this repo 的client 的package.json 中的proxy 有关
任何帮助将不胜感激!
更新
这是代理设置。
This 在某种程度上解决了它。通过删除 "proxy": "http://localhost:3001" 我可以加载网站,但问题中建议的答案对我不起作用。即我现在无法访问我的 API。
【问题讨论】:
标签: reactjs azure express docker