我正在使用 nginx 來提供 angular(index.html) 并且效果很好。問題是我在嘗試與后端通信時不斷出錯。我的 NGINX + Angular DockerfileFROM node:12-alpine as builderWORKDIR /usr/src/appCOPY . .RUN npm install --silentRUN npm run ng build --prodFROM nginx:latestCOPY --from=builder /usr/src/app/dist/FrontEnd /var/wwwCOPY ./default.conf /etc/nginx/nginx.confEXPOSE 80CMD ["nginx", "-g", "daemon off;"]我的 Golang DockerfileFROM golang:latestENV GO111MODULE=onRUN mkdir /appWORKDIR /appCOPY go.mod .COPY go.sum .RUN go mod downloadCOPY . .RUN go build main.goEXPOSE 8000CMD [ "./main" ]我的 Docker-composeversion: '3.7'services: postgres: image: "postgres:latest" restart: always volumes: - ./init.sql:/docker-entrypoint-initdb.d/init.sql - data:/var/lib/postgresql/data ports: - "5432:5432" environment: - POSTGRES_DB=Project - POSTGRES_USER=postgres - POSTGRES_PASSWORD=password networks: - mynet #Back-end golang: build: context: . dockerfile: Dockerfile container_name: golang links: - postgres ports: - "8000:8000" networks: - mynet #Front-end Angular Application angular: links: - golang build: context: ./FrontEnd dockerfile: Dockerfile environment: - host=golang ports: - "4200:80" networks: - mynetvolumes: data:networks: mynet: driver: bridge我的 nginx default.confworker_processes 4;events { worker_connections 1024;}這是我嘗試向 golang [1] 發(fā)送 api 調(diào)用時的結(jié)果:https ://i.stack.imgur.com/XQuhf.png我已經(jīng)被這個問題困擾了好幾天了,而且時間不多了。請幫忙!提前致謝。
1 回答

ibeautiful
TA貢獻1993條經(jīng)驗 獲得超6個贊
golang:8000
只能在 docker 網(wǎng)絡中訪問。您可以通過在瀏覽器中訪問來檢查您的 golang API ,并在您的角度代碼中http://35.238.xx.xx:4200/users/xxx
使用相對 url 。"/users/xxx"
- 1 回答
- 0 關(guān)注
- 145 瀏覽
添加回答
舉報
0/150
提交
取消