问题
The problem I am facing is somewhat known to me but still, I wanted to understand the problem in my implementation.
I have a Traefik container and a service container. The service container has certain routes that serves the pages. In order to pass the request from Traefik to the service/application container,I have attached a label to my container. The label has a path as the one in my application so that Traefik can redirect the request to backend service and finally my service can serve the request.
Main Problem: All works fine and dandy till now but the problem is that my application/service serves some static pages that are on another route not recognizable by Traefik. This will generate an Error 404. I am not able to find a way out of this problem.
Eg: I have a Service A that serves the request on http://localhost/blog and all the further requests go through localhost/blog/* . For this I would simply add the label with PathPrefix(/blog
) It makes everything work but there is no JS and CSS files loaded. The reason for the same is that my css and js files are loaded from the http://localhost/js and http://localhost/css route. Of course this route is not recognized by Traefik.
Docker-Compose.yml
servicea:
container_name: servicea-ge
image: 'servicea'
restart: always
labels:
- traefik.http.routers.servicea.rule=PathPrefix(`/blog`)
networks:
- internal-network
logging:
driver: json-file
options: {max-size: 20m, max-file: '5'}
environment:
TZ: '${Time_Zone}'
networks:
internal-network:
driver: bridge
name: test
I have tried a solution in which I have added a middleware to strip /blog but this will also cause further problems. Now the home page gets loaded successfully but the further routes like /blog/addblog start to fail as blog will be removed (reason strip middleware). Eg:
- traefik.http.routers.servicea.middlewares=strip-blog
- traefik.http.middlewares.strip-blog.stripprefix.prefixes=/blog
Could anyone propose a solution to the above-described problem?
来源:https://stackoverflow.com/questions/61186640/cant-resolve-url-in-traefik-getting-error-404