nginx是否可以在ngninx反向代理docker上动态添加位置?

使用traefik解决了该问题,它允许我通过子目录将路由添加到容器,而无需修改构建配置。

docker-compose.yml将是这样的:

version: '3.7' services: traefik: image: traefik:v2.2.0 ports: - "${FRONT_HTTP_PORT:-80}:80" - "${TRAEFIK_PORT:-8080}:8080" environment:  - TRAEFIK_LOG_LEVEL=DEBUG - TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT=false - TRAEFIK_PROVIDERS_DOCKER=true - TRAEFIK_PROVIDERS_DOCKER_NETWORK=traefik01 - TRAEFIK_API_INSECURE=true - TRAEFIK_ENTRYPOINTS_FRONT=true - TRAEFIK_ENTRYPOINTS_FRONT_ADDRESS=:${FRONT_HTTP_PORT:-80} volumes: - /var/run/docker.sock:/var/run/docker.sock:ro security_opt: - label:type:docker_t  frontend: build: ./frontend expose: - 80 labels: - "traefik.enable=true" - "traefik.http.routers.frontend.entrypoints=front" - "traefik.http.routers.frontend.rule=PathPrefix(`/frontend{regex:$$|/.*}`)" - "traefik.http.routers.frontend.middlewares=frontend-stripprefix" - "traefik.http.middlewares.frontend-stripprefix.stripprefix.prefixes=/frontend" - "traefik.http.routers.frontend.priority=2" # - "traefik.http.routers.frontend.priority=1" # - "traefik.frontend.rule=Host:ctf.itasahobby.com" stdin_open: true  api: build: ./api expose:  - 80 links: - database labels: - "traefik.enable=true" - "traefik.http.routers.api.entrypoints=front" - "traefik.http.routers.api.rule=PathPrefix(`/api{regex:$$|/.*}`)" - "traefik.http.routers.api.middlewares=api-stripprefix" - "traefik.http.middlewares.api-stripprefix.stripprefix.prefixes=/api" - "traefik.http.routers.api.priority=2"  database: build: ./database restart: always networks: default: external: name: testnetwork 

然后,要添加一个新容器,它必须包含相同的网络接口和标签,以便设置路由,例如:

version: '3.7' services: app2: image: httpd:2.4.41-alpine expose: - 80 labels: - "traefik.enable=true" - "traefik.http.routers.app2.entrypoints=front" - "traefik.http.routers.app2.rule=PathPrefix(`/app2{regex:$$|/.*}`)" - "traefik.http.routers.app2.middlewares=app2-stripprefix" - "traefik.http.middlewares.app2-stripprefix.stripprefix.prefixes=/app2" networks: default: external: name: testnetwork  

原文链接:https://www.nuomiphp.com/eplan/690033.html

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享