将NGINX配置为反向代理并连接到后端

问题描述 投票:0回答:1

我有一个simple dockerized flask backend侦听0.0.0.0:8080,并且simple dockerized react frontendlocalhost:8080/api/v1.0/resource发送请求。现在,我想在docker中运行这些容器,然后将请求发送到服务名称backend撰写文件如下所示:

version: '3'
services:
  backend:
    ports:
      - "8080:8080"
    image: "tobiaslocker/simple-dockerized-flask-backend:v0.1"
  frontend:
    ports:
      - "80:80"
    image: "tobiaslocker/simple-dockerized-react-frontend:v0.1"

用于请求NGINXlocalhost配置:

server {
  listen 80;
  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
  }
}

前端发送请求axios.get('http://localhost:8080/api/v1.0/resource')

我的问题:

  1. 我必须如何配置NGINX才能使用服务名称(例如backend
  2. 我必须如何发出请求以匹配配置。

我不确定从前端发送请求并发现难以调试时,proxy_pass将如何生效。

问候

docker nginx docker-compose axios
1个回答
0
投票

您不需要nginx,因为这些图像已在单独的端口中提供。您的前端可以通过http://localhost:8080轻松找到后端api,因为它在端口8080上运行。

© www.soinside.com 2019 - 2024. All rights reserved.