【发布时间】:2020-08-01 03:03:12
【问题描述】:
我正在尝试为个人博客设置微服务架构。
这个想法是让 NGINX 容器为静态 gatsby 站点提供服务,并重定向到其他服务。例如,我想在 /todos 有一个 react 应用,在 /todos_api 有一个用于该 todo 应用的 api。
我目前的文件夹结构是这样的:
- docker-compose.yml
- 盖茨比博客
- (包含构建文件夹)
- nginx
- default.conf(这是我的主要 nginx 条目)
- 投资组合
- 待办事项
- todo_client
- nginx
- default.conf(这仅用于为 react 应用提供服务)
- nginx
- todo_api
- todo_client
- 待办事项
我的 docker-compose 文件如下所示:
version: "3"
services:
gatsby:
restart: always
build:
dockerfile: Dockerfile
context: ./gatsby_blog
ports:
- "80:80"
todoclient:
build:
dockerfile: Dockerfile
context: ./portfolio/todos/todo_client
我的 Gatsby nginx 主文件如下所示:
upstream todoclient {
server todoclient:3000;
}
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /todos {
rewrite /todos/(.*) /$1 break;
proxy_pass http://todoclient;
}
}
我的 React nginx 配置是这样的:
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
我很确定的问题是我的 nginx 配置。当我转到 localhost 时,我遇到了 gatsby 应用程序,但是如果我转到 /todos,我会收到一个 nginx 错误。可以看到请求正确传递到了todoclient容器,但是返回的错误是:
open() "/usr/share/nginx/html/todos" 失败(2:没有那个文件或目录
如果有人能看出我在 nginx 配置上哪里出了问题,我将不胜感激。如果需要,我也可以发布我的 Dockerfile。 谢谢
编辑
我现在已经设法让代理工作了,但问题是 todos 应用程序找不到它的静态文件。它们在容器中的正确位置,并且容器独立工作,因此问题与 docker-compose 和 nginx 代理有关。
【问题讨论】:
标签: reactjs docker nginx docker-compose gatsby