Treafik Path Routing










1















I want to reach a docker-compose service under api.example.com/example. Therefore I have the following docker-compose.yml



 example:
image: example
labels:
- "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/"
- "traefik.enable=true"
- "traefik.protocol=http"
- "traefik.frontend.entryPoints=https"


I can reach the service under this path. But all the links in the page route to a wrong url like api.example.com/link instead of api.example.com/example/link



Also the css is not loading correctly because of this path issue.
What would be the right path configuration to get this working?



Reading from the docs, X-Forwarded-Prefix should be the solution, but there is no doc about.










share|improve this question




























    1















    I want to reach a docker-compose service under api.example.com/example. Therefore I have the following docker-compose.yml



     example:
    image: example
    labels:
    - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/"
    - "traefik.enable=true"
    - "traefik.protocol=http"
    - "traefik.frontend.entryPoints=https"


    I can reach the service under this path. But all the links in the page route to a wrong url like api.example.com/link instead of api.example.com/example/link



    Also the css is not loading correctly because of this path issue.
    What would be the right path configuration to get this working?



    Reading from the docs, X-Forwarded-Prefix should be the solution, but there is no doc about.










    share|improve this question


























      1












      1








      1


      1






      I want to reach a docker-compose service under api.example.com/example. Therefore I have the following docker-compose.yml



       example:
      image: example
      labels:
      - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/"
      - "traefik.enable=true"
      - "traefik.protocol=http"
      - "traefik.frontend.entryPoints=https"


      I can reach the service under this path. But all the links in the page route to a wrong url like api.example.com/link instead of api.example.com/example/link



      Also the css is not loading correctly because of this path issue.
      What would be the right path configuration to get this working?



      Reading from the docs, X-Forwarded-Prefix should be the solution, but there is no doc about.










      share|improve this question
















      I want to reach a docker-compose service under api.example.com/example. Therefore I have the following docker-compose.yml



       example:
      image: example
      labels:
      - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/"
      - "traefik.enable=true"
      - "traefik.protocol=http"
      - "traefik.frontend.entryPoints=https"


      I can reach the service under this path. But all the links in the page route to a wrong url like api.example.com/link instead of api.example.com/example/link



      Also the css is not loading correctly because of this path issue.
      What would be the right path configuration to get this working?



      Reading from the docs, X-Forwarded-Prefix should be the solution, but there is no doc about.







      docker docker-compose reverse-proxy traefik






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 12:24







      Florian

















      asked Nov 13 '18 at 12:05









      FlorianFlorian

      591724




      591724






















          2 Answers
          2






          active

          oldest

          votes


















          0














          If I understand correctly, you only want to route requests matching api.example.com/example/* to this example service. Then you should use PathPrefix:/example/.



          What you have is expected: PathPrefixStrip, as the name suggests, try to match the path, then, remove it before routing traffic to the service.






          share|improve this answer























          • yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

            – Florian
            Nov 13 '18 at 13:09












          • As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

            – Siyu
            Nov 13 '18 at 13:31











          • yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

            – Florian
            Nov 13 '18 at 13:35











          • The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

            – Siyu
            Nov 13 '18 at 13:48











          • When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

            – Siyu
            Nov 13 '18 at 13:49



















          0














          Did you try to add rules ?



          - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/; AddPrefix: /example" 





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280683%2ftreafik-path-routing%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If I understand correctly, you only want to route requests matching api.example.com/example/* to this example service. Then you should use PathPrefix:/example/.



            What you have is expected: PathPrefixStrip, as the name suggests, try to match the path, then, remove it before routing traffic to the service.






            share|improve this answer























            • yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

              – Florian
              Nov 13 '18 at 13:09












            • As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

              – Siyu
              Nov 13 '18 at 13:31











            • yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

              – Florian
              Nov 13 '18 at 13:35











            • The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

              – Siyu
              Nov 13 '18 at 13:48











            • When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

              – Siyu
              Nov 13 '18 at 13:49
















            0














            If I understand correctly, you only want to route requests matching api.example.com/example/* to this example service. Then you should use PathPrefix:/example/.



            What you have is expected: PathPrefixStrip, as the name suggests, try to match the path, then, remove it before routing traffic to the service.






            share|improve this answer























            • yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

              – Florian
              Nov 13 '18 at 13:09












            • As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

              – Siyu
              Nov 13 '18 at 13:31











            • yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

              – Florian
              Nov 13 '18 at 13:35











            • The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

              – Siyu
              Nov 13 '18 at 13:48











            • When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

              – Siyu
              Nov 13 '18 at 13:49














            0












            0








            0







            If I understand correctly, you only want to route requests matching api.example.com/example/* to this example service. Then you should use PathPrefix:/example/.



            What you have is expected: PathPrefixStrip, as the name suggests, try to match the path, then, remove it before routing traffic to the service.






            share|improve this answer













            If I understand correctly, you only want to route requests matching api.example.com/example/* to this example service. Then you should use PathPrefix:/example/.



            What you have is expected: PathPrefixStrip, as the name suggests, try to match the path, then, remove it before routing traffic to the service.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 '18 at 12:41









            SiyuSiyu

            2,4881826




            2,4881826












            • yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

              – Florian
              Nov 13 '18 at 13:09












            • As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

              – Siyu
              Nov 13 '18 at 13:31











            • yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

              – Florian
              Nov 13 '18 at 13:35











            • The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

              – Siyu
              Nov 13 '18 at 13:48











            • When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

              – Siyu
              Nov 13 '18 at 13:49


















            • yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

              – Florian
              Nov 13 '18 at 13:09












            • As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

              – Siyu
              Nov 13 '18 at 13:31











            • yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

              – Florian
              Nov 13 '18 at 13:35











            • The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

              – Siyu
              Nov 13 '18 at 13:48











            • When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

              – Siyu
              Nov 13 '18 at 13:49

















            yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

            – Florian
            Nov 13 '18 at 13:09






            yes but my service behind is listening on / not on /example/ so I have to strip the example, so this will not work, no?

            – Florian
            Nov 13 '18 at 13:09














            As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

            – Siyu
            Nov 13 '18 at 13:31





            As far as I know, servers don't listen to a path, they always "listen" to / (they are on a host). Your apis, though, can be on any path you like, leaving / to a 404 page.

            – Siyu
            Nov 13 '18 at 13:31













            yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

            – Florian
            Nov 13 '18 at 13:35





            yeah this is right, but I therefore use traefik. I want to have several servers listening on / but path routed by traefik. I thought PathPrefixStrip is exactly therefore. Instead, I would not understand the use of traefik with paths

            – Florian
            Nov 13 '18 at 13:35













            The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

            – Siyu
            Nov 13 '18 at 13:48





            The goal here is to have a finer grade scaling control, decoupling the system (concept of microservice) while appear to the outside world as one server.

            – Siyu
            Nov 13 '18 at 13:48













            When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

            – Siyu
            Nov 13 '18 at 13:49






            When you say you want to have several servers listening on /, do you mean that a server A and a server both respond to domain/test ?

            – Siyu
            Nov 13 '18 at 13:49














            0














            Did you try to add rules ?



            - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/; AddPrefix: /example" 





            share|improve this answer



























              0














              Did you try to add rules ?



              - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/; AddPrefix: /example" 





              share|improve this answer

























                0












                0








                0







                Did you try to add rules ?



                - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/; AddPrefix: /example" 





                share|improve this answer













                Did you try to add rules ?



                - "traefik.frontend.rule=Host:api.example.com;PathPrefixStrip:/example/; AddPrefix: /example" 






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 22:03









                DamDamDamDam

                11




                11



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280683%2ftreafik-path-routing%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto