nginx反向代理在docker-comopse中找不到后端服务

vmdwslir  于 2024-01-06  发布在  Nginx
关注(0)|答案(1)|浏览(320)

我有以下docker-compose.yaml

  1. version: '3'
  2. services:
  3. webapp:
  4. image: example/webapp
  5. build:
  6. context: app
  7. restart: always
  8. ports:
  9. - ":8181"
  10. deploy:
  11. replicas: 3
  12. volumes:
  13. - secret-store:/app/data
  14. env_file:
  15. - .env
  16. networks:
  17. - bridged_network
  18. nginx:
  19. image: example/reverseproxy
  20. build:
  21. context: reverseproxy
  22. ports:
  23. - "8181:80"
  24. depends_on:
  25. - webapp
  26. networks:
  27. bridged_network:
  28. driver: bridge
  29. volumes:
  30. secret-store:

字符串
nginx映像的构建过程如下

  1. FROM nginx:latest
  2. RUN rm /etc/nginx/conf.d/*
  3. COPY nginx.conf /etc/nginx/conf.d/default.conf


其中nginx.conf

  1. server {
  2. listen 80;
  3. location / {
  4. proxy_pass http://webapp:8181;
  5. }
  6. }


但是在nginx容器日志中:

  1. nginx: [emerg] host not found in upstream "webapp" in /etc/nginx/conf.d/default.conf:6


为什么nginx无法发现webapp服务?

hgtggwj0

hgtggwj01#

你的nginx反向代理和服务在同一个网络中吗?看起来它们不在同一个网络中。

相关问题