nginx multiple http/https proxy domains The Next CEO of Stack OverflowProxy HTTPS requests to a HTTP backend with NGINXNginx proxy pass works for https but not httpnginx load balancer rewrite to listen portnginx proxy redirecting request to different proxyNginx subversion commit failureNginx/Apache: set HSTS only if X-Forwarded-Proto is httpsIssue serving multiple SSL certs via nginxConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsAnsible to loop over grouped itemsNginx reverse proxy to many local servers + webserver duty

How to count occurrences of text in a file?

How to make a variable always equal to the result of some calculations?

Can we say or write : "No, it'sn't"?

How to start emacs in "nothing" mode (`fundamental-mode`)

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Should I tutor a student who I know has cheated on their homework?

What was the first Unix version to run on a microcomputer?

Non-deterministic sum of floats

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Interfacing a button to MCU (and PC) with 50m long cable

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Why has the US not been more assertive in confronting Russia in recent years?

How fast would a person need to move to trick the eye?

Would a completely good Muggle be able to use a wand?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?

Novel about a guy who is possessed by the divine essence and the world ends?

Does it take more energy to get to Venus or to Mars?

What's the best way to handle refactoring a big file?

Can you replace a racial trait cantrip when leveling up?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Indicator light circuit

calculus parametric curve length



nginx multiple http/https proxy domains



The Next CEO of Stack OverflowProxy HTTPS requests to a HTTP backend with NGINXNginx proxy pass works for https but not httpnginx load balancer rewrite to listen portnginx proxy redirecting request to different proxyNginx subversion commit failureNginx/Apache: set HSTS only if X-Forwarded-Proto is httpsIssue serving multiple SSL certs via nginxConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsAnsible to loop over grouped itemsNginx reverse proxy to many local servers + webserver duty










1















I have a server that is going to host many sites, but right now there are just two. site1 (http://site1.com) is http and site2 (https://site2.com) is https. Both of these sites are node.js based and running off different ports, and I use nginx's proxy_pass to route the domain to the port.



The problem i'm having right now is that you can navigate to https://site1.com but it loads the website for site2 as https://site1.com. Obviously this is not good, as google has indexed the https pages under the wrong domain.



I'm not good with nginx yet, but my current config must be saying to route all https traffic to this port. In the future i'll have multiple https and http sites and obviously all the traffic needs to route properly.



Can anyone take a look at my config and school me as to what i'm doing wrong here?



My nginx.conf file is the default



here is my http://site1.com config



server

listen 80;
listen [::]:80;
server_name site1.com www.site1.com;

location /

proxy_pass http://127.0.0.1:3103;
include /etc/nginx/proxy_params;




and here is my https://site2.com config



server 
listen 80;
listen [::]:80;
server_name site2.com www.site2.com;
return 301 https://$host$request_uri;


server
listen 443 ssl;
server_name site2.com;

ssl_certificate /etc/nginx/ssl/site2_com.crt;
ssl_certificate_key /etc/nginx/ssl/site2_com.key;

location /
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_pass "http://127.0.0.1:3101";

# rewrite redirects to http as to https
proxy_redirect http:// https://;




Any advice and questions are welcome! Let me know if you need anymore context. Thanks!










share|improve this question


























    1















    I have a server that is going to host many sites, but right now there are just two. site1 (http://site1.com) is http and site2 (https://site2.com) is https. Both of these sites are node.js based and running off different ports, and I use nginx's proxy_pass to route the domain to the port.



    The problem i'm having right now is that you can navigate to https://site1.com but it loads the website for site2 as https://site1.com. Obviously this is not good, as google has indexed the https pages under the wrong domain.



    I'm not good with nginx yet, but my current config must be saying to route all https traffic to this port. In the future i'll have multiple https and http sites and obviously all the traffic needs to route properly.



    Can anyone take a look at my config and school me as to what i'm doing wrong here?



    My nginx.conf file is the default



    here is my http://site1.com config



    server

    listen 80;
    listen [::]:80;
    server_name site1.com www.site1.com;

    location /

    proxy_pass http://127.0.0.1:3103;
    include /etc/nginx/proxy_params;




    and here is my https://site2.com config



    server 
    listen 80;
    listen [::]:80;
    server_name site2.com www.site2.com;
    return 301 https://$host$request_uri;


    server
    listen 443 ssl;
    server_name site2.com;

    ssl_certificate /etc/nginx/ssl/site2_com.crt;
    ssl_certificate_key /etc/nginx/ssl/site2_com.key;

    location /
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    proxy_pass "http://127.0.0.1:3101";

    # rewrite redirects to http as to https
    proxy_redirect http:// https://;




    Any advice and questions are welcome! Let me know if you need anymore context. Thanks!










    share|improve this question
























      1












      1








      1








      I have a server that is going to host many sites, but right now there are just two. site1 (http://site1.com) is http and site2 (https://site2.com) is https. Both of these sites are node.js based and running off different ports, and I use nginx's proxy_pass to route the domain to the port.



      The problem i'm having right now is that you can navigate to https://site1.com but it loads the website for site2 as https://site1.com. Obviously this is not good, as google has indexed the https pages under the wrong domain.



      I'm not good with nginx yet, but my current config must be saying to route all https traffic to this port. In the future i'll have multiple https and http sites and obviously all the traffic needs to route properly.



      Can anyone take a look at my config and school me as to what i'm doing wrong here?



      My nginx.conf file is the default



      here is my http://site1.com config



      server

      listen 80;
      listen [::]:80;
      server_name site1.com www.site1.com;

      location /

      proxy_pass http://127.0.0.1:3103;
      include /etc/nginx/proxy_params;




      and here is my https://site2.com config



      server 
      listen 80;
      listen [::]:80;
      server_name site2.com www.site2.com;
      return 301 https://$host$request_uri;


      server
      listen 443 ssl;
      server_name site2.com;

      ssl_certificate /etc/nginx/ssl/site2_com.crt;
      ssl_certificate_key /etc/nginx/ssl/site2_com.key;

      location /
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;

      proxy_pass "http://127.0.0.1:3101";

      # rewrite redirects to http as to https
      proxy_redirect http:// https://;




      Any advice and questions are welcome! Let me know if you need anymore context. Thanks!










      share|improve this question














      I have a server that is going to host many sites, but right now there are just two. site1 (http://site1.com) is http and site2 (https://site2.com) is https. Both of these sites are node.js based and running off different ports, and I use nginx's proxy_pass to route the domain to the port.



      The problem i'm having right now is that you can navigate to https://site1.com but it loads the website for site2 as https://site1.com. Obviously this is not good, as google has indexed the https pages under the wrong domain.



      I'm not good with nginx yet, but my current config must be saying to route all https traffic to this port. In the future i'll have multiple https and http sites and obviously all the traffic needs to route properly.



      Can anyone take a look at my config and school me as to what i'm doing wrong here?



      My nginx.conf file is the default



      here is my http://site1.com config



      server

      listen 80;
      listen [::]:80;
      server_name site1.com www.site1.com;

      location /

      proxy_pass http://127.0.0.1:3103;
      include /etc/nginx/proxy_params;




      and here is my https://site2.com config



      server 
      listen 80;
      listen [::]:80;
      server_name site2.com www.site2.com;
      return 301 https://$host$request_uri;


      server
      listen 443 ssl;
      server_name site2.com;

      ssl_certificate /etc/nginx/ssl/site2_com.crt;
      ssl_certificate_key /etc/nginx/ssl/site2_com.key;

      location /
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;

      proxy_pass "http://127.0.0.1:3101";

      # rewrite redirects to http as to https
      proxy_redirect http:// https://;




      Any advice and questions are welcome! Let me know if you need anymore context. Thanks!







      nginx centos node.js proxypass






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Shan RobertsonShan Robertson

      1104




      1104




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Nginx always has a default server it uses to process requests where the server_name does not match. If you do not specify one explicitly using the default_server attribute, it will choose the first one with a matching listen directive.



          In your case, the server block for site2 is used to process any https connection, albeit with an invalid certificate warning.



          You can define a "catch all" server block, so that the server_name must match for each of your legitimate server blocks.



          For example:



          server 
          listen 80 default_server;
          listen 443 ssl default_server;
          return 444;



          It will work fine for http connections. However, https connections are always problematic, as you cannot be expected to have valid certificates for every bogus domain name that points to your server. This will at least prevent the wrong server block from handling a request.



          See this document for details.






          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "2"
            ;
            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%2fserverfault.com%2fquestions%2f960504%2fnginx-multiple-http-https-proxy-domains%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 always has a default server it uses to process requests where the server_name does not match. If you do not specify one explicitly using the default_server attribute, it will choose the first one with a matching listen directive.



            In your case, the server block for site2 is used to process any https connection, albeit with an invalid certificate warning.



            You can define a "catch all" server block, so that the server_name must match for each of your legitimate server blocks.



            For example:



            server 
            listen 80 default_server;
            listen 443 ssl default_server;
            return 444;



            It will work fine for http connections. However, https connections are always problematic, as you cannot be expected to have valid certificates for every bogus domain name that points to your server. This will at least prevent the wrong server block from handling a request.



            See this document for details.






            share|improve this answer



























              0














              Nginx always has a default server it uses to process requests where the server_name does not match. If you do not specify one explicitly using the default_server attribute, it will choose the first one with a matching listen directive.



              In your case, the server block for site2 is used to process any https connection, albeit with an invalid certificate warning.



              You can define a "catch all" server block, so that the server_name must match for each of your legitimate server blocks.



              For example:



              server 
              listen 80 default_server;
              listen 443 ssl default_server;
              return 444;



              It will work fine for http connections. However, https connections are always problematic, as you cannot be expected to have valid certificates for every bogus domain name that points to your server. This will at least prevent the wrong server block from handling a request.



              See this document for details.






              share|improve this answer

























                0












                0








                0







                Nginx always has a default server it uses to process requests where the server_name does not match. If you do not specify one explicitly using the default_server attribute, it will choose the first one with a matching listen directive.



                In your case, the server block for site2 is used to process any https connection, albeit with an invalid certificate warning.



                You can define a "catch all" server block, so that the server_name must match for each of your legitimate server blocks.



                For example:



                server 
                listen 80 default_server;
                listen 443 ssl default_server;
                return 444;



                It will work fine for http connections. However, https connections are always problematic, as you cannot be expected to have valid certificates for every bogus domain name that points to your server. This will at least prevent the wrong server block from handling a request.



                See this document for details.






                share|improve this answer













                Nginx always has a default server it uses to process requests where the server_name does not match. If you do not specify one explicitly using the default_server attribute, it will choose the first one with a matching listen directive.



                In your case, the server block for site2 is used to process any https connection, albeit with an invalid certificate warning.



                You can define a "catch all" server block, so that the server_name must match for each of your legitimate server blocks.



                For example:



                server 
                listen 80 default_server;
                listen 443 ssl default_server;
                return 444;



                It will work fine for http connections. However, https connections are always problematic, as you cannot be expected to have valid certificates for every bogus domain name that points to your server. This will at least prevent the wrong server block from handling a request.



                See this document for details.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                Richard SmithRichard Smith

                6,5282717




                6,5282717



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Server Fault!


                    • 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%2fserverfault.com%2fquestions%2f960504%2fnginx-multiple-http-https-proxy-domains%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

                    Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                    Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                    What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company