Dynamic Nginx proxy with Docker












1















I'm stucking with configuring a Nginx instance embedded in a Docker container which should implement a dynamic reverse proxy for not-enabled CORS web sites.



I was expecting it was an easy task, but it doesn't work under some conditions. This is a working location block:



location ~* ^/proxy/(.*) {


proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect off;

proxy_pass https://google.com;
}


This configuration works. The google page appears. So it seems Docker is able to resolve google name.



This configuration (which I'm more interested to) doesn't work:



   location ~* ^/proxy/(.*) {

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect off;

proxy_pass http://$1$is_args$args;
}


It seems that Docker is not able to resolve the name extracted by the first regex group.



If I add in the location block the resolver directive it starts working.



      location ~* ^/proxy/(.*) {
resolver 192.168.31.2;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect off;

proxy_pass http://$1$is_args$args;
}


So, where's the difference? Why the resolver directive is needed? Why in the first case (if the proxy path name is hardcoded) everything's working while not in the other case? Is the host resolv.conf file should be used inside the container itself?



I also tried to create the container passing the --dns option but still not working.



Ideas?
Thanks,
Fb










share|improve this question



























    1















    I'm stucking with configuring a Nginx instance embedded in a Docker container which should implement a dynamic reverse proxy for not-enabled CORS web sites.



    I was expecting it was an easy task, but it doesn't work under some conditions. This is a working location block:



    location ~* ^/proxy/(.*) {


    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_redirect off;

    proxy_pass https://google.com;
    }


    This configuration works. The google page appears. So it seems Docker is able to resolve google name.



    This configuration (which I'm more interested to) doesn't work:



       location ~* ^/proxy/(.*) {

    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_redirect off;

    proxy_pass http://$1$is_args$args;
    }


    It seems that Docker is not able to resolve the name extracted by the first regex group.



    If I add in the location block the resolver directive it starts working.



          location ~* ^/proxy/(.*) {
    resolver 192.168.31.2;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_redirect off;

    proxy_pass http://$1$is_args$args;
    }


    So, where's the difference? Why the resolver directive is needed? Why in the first case (if the proxy path name is hardcoded) everything's working while not in the other case? Is the host resolv.conf file should be used inside the container itself?



    I also tried to create the container passing the --dns option but still not working.



    Ideas?
    Thanks,
    Fb










    share|improve this question

























      1












      1








      1








      I'm stucking with configuring a Nginx instance embedded in a Docker container which should implement a dynamic reverse proxy for not-enabled CORS web sites.



      I was expecting it was an easy task, but it doesn't work under some conditions. This is a working location block:



      location ~* ^/proxy/(.*) {


      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_redirect off;

      proxy_pass https://google.com;
      }


      This configuration works. The google page appears. So it seems Docker is able to resolve google name.



      This configuration (which I'm more interested to) doesn't work:



         location ~* ^/proxy/(.*) {

      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_redirect off;

      proxy_pass http://$1$is_args$args;
      }


      It seems that Docker is not able to resolve the name extracted by the first regex group.



      If I add in the location block the resolver directive it starts working.



            location ~* ^/proxy/(.*) {
      resolver 192.168.31.2;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_redirect off;

      proxy_pass http://$1$is_args$args;
      }


      So, where's the difference? Why the resolver directive is needed? Why in the first case (if the proxy path name is hardcoded) everything's working while not in the other case? Is the host resolv.conf file should be used inside the container itself?



      I also tried to create the container passing the --dns option but still not working.



      Ideas?
      Thanks,
      Fb










      share|improve this question














      I'm stucking with configuring a Nginx instance embedded in a Docker container which should implement a dynamic reverse proxy for not-enabled CORS web sites.



      I was expecting it was an easy task, but it doesn't work under some conditions. This is a working location block:



      location ~* ^/proxy/(.*) {


      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_redirect off;

      proxy_pass https://google.com;
      }


      This configuration works. The google page appears. So it seems Docker is able to resolve google name.



      This configuration (which I'm more interested to) doesn't work:



         location ~* ^/proxy/(.*) {

      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_redirect off;

      proxy_pass http://$1$is_args$args;
      }


      It seems that Docker is not able to resolve the name extracted by the first regex group.



      If I add in the location block the resolver directive it starts working.



            location ~* ^/proxy/(.*) {
      resolver 192.168.31.2;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_redirect off;

      proxy_pass http://$1$is_args$args;
      }


      So, where's the difference? Why the resolver directive is needed? Why in the first case (if the proxy path name is hardcoded) everything's working while not in the other case? Is the host resolv.conf file should be used inside the container itself?



      I also tried to create the container passing the --dns option but still not working.



      Ideas?
      Thanks,
      Fb







      docker nginx reverse-proxy nginx-reverse-proxy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 9:01









      FrankBrFrankBr

      50511226




      50511226
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Nginx try to resolve domain_name with upstream directive: if it fail it will try to use resolver to solve your name as DNS. So, in the end, you need to set resolver directive.






          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%2f53315717%2fdynamic-nginx-proxy-with-docker%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Nginx try to resolve domain_name with upstream directive: if it fail it will try to use resolver to solve your name as DNS. So, in the end, you need to set resolver directive.






            share|improve this answer




























              0














              Nginx try to resolve domain_name with upstream directive: if it fail it will try to use resolver to solve your name as DNS. So, in the end, you need to set resolver directive.






              share|improve this answer


























                0












                0








                0







                Nginx try to resolve domain_name with upstream directive: if it fail it will try to use resolver to solve your name as DNS. So, in the end, you need to set resolver directive.






                share|improve this answer













                Nginx try to resolve domain_name with upstream directive: if it fail it will try to use resolver to solve your name as DNS. So, in the end, you need to set resolver directive.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 10:07









                Claudio PomoClaudio Pomo

                94952457




                94952457
































                    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%2f53315717%2fdynamic-nginx-proxy-with-docker%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







                    Popular posts from this blog

                    The Sandy Post

                    Danny Elfman

                    Pages that link to "Head v. Amoskeag Manufacturing Co."