Bypass response codes?

Hi Folks,

here is my situation:

i migrated nexus from a nginx setup to a traefik environment.

old urls contain /nexus

new urls should not have a context path.

i managed to write redirection rules that forward all requests to url with context path to the new one without.

Browser requests work without any issue (using GET header)

but any upload requests (i.e. maven) are not allowed to follow redirects when POST header is used.

is it possible to make traefik respond with 200 instead 302 (permanently redirected) i.e. like a silent redirect ?

thanks in advance

Share your full Traefik static and dynamic config, and Docker compose file(s) if used.

hi bluepuma77

docker-compose.yml

services:
  traefik:
    image: traefik:latest
    container_name: traefik
    restart: always
    entrypoint:
      - /bin/sh
      - -c
      - |
        cp /certs/suva-root-ca.crt /usr/local/share/ca-certificates/ && \
        update-ca-certificates && \
        exec traefik --configFile=/etc/traefik/traefik.yml
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - ./traefik.yml:/etc/traefik/traefik.yml:ro
      - ./dynamic.yml:/etc/traefik/dynamic.yml:ro
      - ./certs/acme.json:/acme/acme.json
      - ./certs/suva-root-ca.crt:/certs/suva-root-ca.crt:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefik
    environment:
      - NO_PROXY=localhost,127.0.0.1,suvanet.ch,.suvanet.ch
networks:
  traefik:
    external: true

dynamic.yml

http:
  middlewares:
    redirect-to-https:
      redirectScheme:
        scheme: https
        permanent: true

  routers:
    http-catchall:
      rule: "HostRegexp(`{host:.+}`)"
      entryPoints:
        - web
      middlewares:
        - redirect-to-https
      service: noop@internal

traefik.yml

global:
  checkNewVersion: false

api:
  insecure: true
  dashboard: true
  debug: true

log:
  level: DEBUG

entryPoints:
  web:
    address: ":80"
  websecure:
    address: ":443"

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false

  file:
    filename: /etc/traefik/dynamic.yml
    watch: true

certificatesResolvers:
  custom-acme:
    acme:
      email: "GO-SAFe-Unity@suva.ch"
      storage: /acme/acme.json
      caServer: "https://pkiacme.suvanet.ch:21443/acme/ws/Acme.svc/webserver/directory"
      httpChallenge:
        entryPoint: "web"

Regarding wording: a "redirect" is sent by the server to the client, telling it to use a different URL. This can not be done silently. Are you talking about proxying/forwarding the request?

You didn’t Post dynamic config of the service with the problem. I assume you use stripPrefix middleware. The challenge is that some services insist on their path, and they will always respond with a redirect, unless you can configure them with some kind of new base path.

Personally I would just leave the context path in place if everything works, instead of hour-long re-configuration.

Note that you overwrite the Docker entrypoint, which might have unintended side effects. Signals may not be forwarded, Traefik might not close ports for new connections during shutdown, and you may lose requests during upgrades despite a HA setup.