containous / traefik-library-image

ARCHIVED
https://github.com/traefik/traefik-library-image
Apache License 2.0
218 stars 60 forks source link

Routing Docker Swarm #78

Closed acountrec closed 4 years ago

acountrec commented 4 years ago

I'm sorry for posting it here, I'm sure it's not an issue but I'm doing something wrong but I'm quite desperate.

I have a django app and want to load static files by nginx. But somehow the routing refuses to go to nginx for anything. nginx shows 0 logs of activity, as if traefik is not talking to that service.

Here's my code:

web-nginx.yml:


services:
  web:
    #build: ./web
    image: web:production
    command: gunicorn web.wsgi:application --bind 0.0.0.0:8000
    volumes:
      - static_volume:/usr/src/app/static
    ports:
      - "8000:8000"
    networks:
      - traefik-public
    env_file:
      - .env
    #depends_on:
    #  - migration_and_static
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.web.rule=Host(`example`)"
        - "traefik.http.routers.web.entrypoints=websecure"
        - "traefik.http.routers.static.priority=1"
        - "traefik.http.routers.web.tls.certresolver=letsencryptresolver"
        - "traefik.http.services.web.loadbalancer.server.port=8000"
      update_config:
        delay: 10s

  static:
   image: nginx
   volumes:
     - static_volume:/usr/share/nginx/html:ro
   networks:
     - traefik-public
   labels:
     - "traefik.enable=true"
     - "traefik.http.routers.static.rule=Host(`example.com`) && PathPrefix(`/static`)"
     - "traefik.http.routers.static.entrypoints=websecure"
     - "traefik.http.routers.static.service=static"
     - "traefik.http.routers.static.priority=200"
     - "traefik.http.routers.static.tls.certresolver=letsencryptresolver"
     - "traefik.http.services.static.loadbalancer.server.port=8080"
     - "traefik.http.middlewares.static-stripprefix.stripprefix.prefixes=/static"

     # Match on the hostname and the path
     # - traefik.enable=true
     # - traefik.http.routers.static.rule=(Host(`example.com`) && Path(`/static`))
     # - traefik.http.routers.static.tls=true
     # - traefik.http.routers.static.tls.certresolver=le
     # - traefik.http.services.static.loadbalancer.server.port=80

     # # Define a new middleware to strip the URL prefix before sending it to static-files
     # - traefik.http.middlewares.static-stripprefix.stripprefix.prefixes=/static

     # tell Traefik which middlewares we want to use on this container
     # - traefik.http.routers.static.middlewares=gzip@docker,static-stripprefix@docker

   #depends_on:
   #  - web

volumes:
  static_volume:

networks:
  traefik-public:
    external: true

traefik.yml:


services:
  reverse-proxy:
    image: traefik:v2.2.0
    command:
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.docker.swarmMode=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.network=traefik-public"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.letsencryptresolver.acme.httpchallenge=true"
      - "--certificatesresolvers.letsencryptresolver.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.letsencryptresolver.acme.email=myemail@example.com"
      - "--certificatesresolvers.letsencryptresolver.acme.storage=/letsencrypt/acme.json"
    ports:
      - 80:80
      - 443:443
    volumes:
      - traefik-certificates:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefik-public
    deploy:
      placement:
        constraints:
          - node.role == manager
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
        - "traefik.http.routers.http-catchall.entrypoints=web"
        - "traefik.http.routers.http-catchall.middlewares=redirect-to-https@docker"
        - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
        - "traefik.http.services.static-http.loadbalancer.server.port=443"

volumes:
  traefik-certificates:
networks:
  traefik-public:
    external: true

Sorry once again, don't know where else to go

Thanks! Sam

ldez commented 4 years ago

Hello,

to get help come to the community forum