【发布时间】:2021-09-28 19:04:45
【问题描述】:
我正在尝试 dockerize 我的个人应用程序。通常在本地我们会在 react 的 package.json 文件中提到服务器(http://server:4000)。但是在生产中,当我们构建 react 应用程序时,我们不使用 pacakge.json。我们必须配置 nginx 服务器以将 api 调用重定向到我的节点 js 服务器。
这是我的 nginx 配置和容器。
容器: 容器 ID 图像命令创建状态端口 名称 10b8d0bf6b2e abc/client:latest "/docker-entrypoint...." 43 分钟前 Up 27 分钟 0.0.0.0:8001->80/tcp, :::8001->80/tcp 客户 ed73637b394d abc/api:latest "node index.js" 5 天前 上升 39 分钟 0.0.0.0:4000->4000/tcp, :::4000->4000/tcp 节点 6ead7807604a mongo "docker-entrypoint.s…" 6 天前 上升 42 分钟 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp 分贝
【问题讨论】:
-
Nginx 配置: 上游 api { 服务器节点:4000; } 服务器 { 听 80;听[::]: 80;位置/{根/var/www/html;索引 index.html 索引.htm; try_files $uri / index.html; proxy_pass http://api; proxy_set_header 主机 $http_host; } error_page 404 / 404.html; error_page 403 / 403. html; # 允许在静态页面上进行 POST error_page 405 = 200 $uri; }
标签: node.js reactjs docker nginx