surajm
September 4, 2023, 11:10am
1
I have sync & async rest apis in Spring Boot container.
User sends the request to port 9182 and traefik forwards this request to backend spring-boot container.
But it returns 302 status code.
Same async rest api is working fine if I run directly inside from spring-boot container.
Even, sync rest API are working fine from outside of container forwarded via Traefik.
Only Async rest apis are throwing this 302 status code when ran from outside.
Is there any specific config for Async rest API?
Share your full Traefik static and dynamic config, and docker-compose.yml
if used.
Format your code with 3 backticks in front and after, or select the code and press </>
. In yaml every space matters. And it makes it so much more readable for people trying to help you.
In the meantime, check this simple Traefik example .
surajm
September 5, 2023, 7:00am
3
Hi @bluepuma77
Please see the config below:
Traefik.yaml file:
version: "3.8"
networks:
core-net:
external: true
services:
loadbalancer:
image: "traefik:v2.4.8"
command:
- "--log.level=DEBUG"
- "--providers.docker=true"
- "--providers.docker.swarmMode=true"
- "--providers.docker.watch=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.file.filename=/dynamic-conf.toml"
- "--api.insecure=true"
- "--log.filePath=/var/log/vnms/traefik/traefik.log"
- "--accessLog.filePath=/var/log/vnms/traefik/access.log"
- "--entrypoints.web-secure.address=:443"
- "--entrypoints.web.address=:80"
- "--entrypoints.backend-rest.address=:9182"
ports:
- '8010:8080'
- '8070:8080'
- '80:80'
- '443:443'
- '9182:9182'
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "/var/tmp/vnms/share/config/manifest/dynamic-conf.toml:/dynamic-conf.toml"
- "/var/tmp/vnms/share/certs/:/certs/"
- "/var/log/vnms/traefik:/var/log/vnms/traefik"
- "/etc/localtime:/etc/localtime:ro"
- "/etc/timezone:/etc/timezone:ro"
deploy:
restart_policy:
condition: any
mode: global
networks:
- core-net
dynamic-conf.toml file:
[tls.options]
[tls.options.default]
minVersion = "VersionTLS12"
cipherSuites = [
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_AES_256_GCM_SHA384",
"TLS_CHACHA20_POLY1305_SHA256",
"TLS_AES_128_GCM_SHA256"
]
[[tls.certificates]]
certFile = "/certs/abc.crt"
keyFile = "/certs/abc.key"
stores = ["default"]
[tls.stores]
[tls.stores.default]
[tls.stores.default.defaultCertificate]
certFile = "/certs/abc.crt"
keyFile = "/certs/abc.key"
spring-boot.yml file having rest API hosted:
version: '3.8'
volumes:
ncs-data:
external: true
networks:
mgmt-net:
external: true
core-net:
external: true
kafka-net:
external: true
services:
backend-service:
image: 'spring-boot:latest'
ports:
- '8002:8002'
- '9090:9090'
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: bind
source: /var/log/vnms
target: /var/log/vnms
networks:
- core-net
- kafka-net
deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=core-net"
- "traefik.backend-service.port=9182"
- "traefik.http.routers.backend-secure.entrypoints=backend-rest"
- "traefik.http.routers.backend-secure.rule=Host(`0.0.0.0`)||hostregexp(`{host:.+}`)||PathPrefix(`/`, )"
- "traefik.http.routers.backend-secure.service=backend-service"
- "traefik.http.services.backend-service.loadbalancer.sticky.cookie=false"
- "traefik.http.services.backend-service.loadbalancer.server.port=9182"
- "traefik.http.routers.backend-secure.tls=true"
- "traefik.http.routers.backend-secure.tls.options=default"
restart_policy:
condition: any