nginx - Disable HTTPS redirection for specific URLNode.js + Nginx - What now?Vagrant / puppet config for complex vhost setting (if statements etc.)?Can multi laravel based sites be accessed by folder not by port?Share Nginx server configurationWordpress constant redirect with nginx upstreamELB Nginx redirect http to httpsKeycloak Redirect url with nginx is going to http rather than httpsNginx with PhpMyAdmin (Secured via ssl)Strange Nginx behavior with trailing slashesUnable to redirect http://example.com to https://www.example.com using nginx on Laravel Forge

What minifigure is this?

Why do we need common sense in AI?

Chorophyll and photosynthesis in plants with coloured leaves

How to know if blackberries are safe to eat

Is it okay to roll multiple attacks that all have advantage in one cluster?

What is the correct parsing of お高くとまる?

Why does wrapping Aluminium foil around my food help it keep warm, aluminium be good conductor should have no effect?

Misspelling my name on my mathematical publications

How can I effectively communicate to recruiters that a phone call is not possible?

Why is Nibbana referred to as "The destination and the path leading to the destination"?

Can I play a mimic PC?

Swapping "Good" and "Bad"

What is a "Lear Processor" and how did it work?

What happens when adult Billy Batson says "Shazam"?

Why does every calorie tracking app give a different target calorie count for the same goals?

What is the parallel of Day of the Dead with Stranger things?

What the real concept of Static keyword in perspective of Embedded C. See below code

Why did Old English lose both thorn and eth?

Why did Harry Potter get a bedroom?

Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?

Is there a minimum field size for peah to apply?

Is there any reason why MCU changed the Snap to Blip

How to drill holes in 3/8" steel plates?

How quality assurance engineers test calculations?



nginx - Disable HTTPS redirection for specific URL


Node.js + Nginx - What now?Vagrant / puppet config for complex vhost setting (if statements etc.)?Can multi laravel based sites be accessed by folder not by port?Share Nginx server configurationWordpress constant redirect with nginx upstreamELB Nginx redirect http to httpsKeycloak Redirect url with nginx is going to http rather than httpsNginx with PhpMyAdmin (Secured via ssl)Strange Nginx behavior with trailing slashesUnable to redirect http://example.com to https://www.example.com using nginx on Laravel Forge






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have nginx setup to redirect all HTTP requests to HTTPS like so:



# Redirect every request to HTTPS...
server
listen 80;
listen [::]:80;

server_name .sub.example.com;
return 301 https://$host$request_uri;



I have a requirement for a specific route to not be forced to HTTPS /iot/token/weather.



I tried updating the nginx config like so:



# Redirect every request to HTTPS...
server
listen 80;
listen [::]:80;

location ~* ^/iot/[0-9a-z]/weather$
break;


server_name .sub.example.com;
return 301 https://$host$request_uri;



However the HTTP request was still being forced to HTTPS.



So I tried doing this:



# Redirect every request to HTTPS...
server
listen 80;
listen [::]:80;

server_name .sub.example.com;

location ~* ^/iot/[0-9a-z]/weather$
break;


location /
return 301 https://$host$request_uri;




However this still isn't working.



The above is the only file imported in the before section below:



# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/sub.example.com/before/*;

server
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name sub.example.com;
root /home/forge/sub.example.com/public;

# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/sub.example.com/467330/server.crt;
ssl_certificate_key /etc/nginx/ssl/sub.example.com/467330/server.key;

ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.html index.htm index.php;

charset utf-8;

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/sub.example.com/server/*;

location /
try_files $uri $uri/ /index.php?$query_string;


location = /favicon.ico access_log off; log_not_found off;
location = /robots.txt access_log off; log_not_found off;

access_log off;
error_log /var/log/nginx/sub.example.com-error.log error;

error_page 404 /index.php;

location ~ .php$
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;


location ~ /.(?!well-known).*
deny all;



# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/sub.example.com/after/*;


I'd appreciate some help setting this up so that I can specify a URL to match that should not be redirected to HTTPS and then have all other URLs redirect to HTTPS.










share|improve this question






























    0















    I have nginx setup to redirect all HTTP requests to HTTPS like so:



    # Redirect every request to HTTPS...
    server
    listen 80;
    listen [::]:80;

    server_name .sub.example.com;
    return 301 https://$host$request_uri;



    I have a requirement for a specific route to not be forced to HTTPS /iot/token/weather.



    I tried updating the nginx config like so:



    # Redirect every request to HTTPS...
    server
    listen 80;
    listen [::]:80;

    location ~* ^/iot/[0-9a-z]/weather$
    break;


    server_name .sub.example.com;
    return 301 https://$host$request_uri;



    However the HTTP request was still being forced to HTTPS.



    So I tried doing this:



    # Redirect every request to HTTPS...
    server
    listen 80;
    listen [::]:80;

    server_name .sub.example.com;

    location ~* ^/iot/[0-9a-z]/weather$
    break;


    location /
    return 301 https://$host$request_uri;




    However this still isn't working.



    The above is the only file imported in the before section below:



    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/sub.example.com/before/*;

    server
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name sub.example.com;
    root /home/forge/sub.example.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/sub.example.com/467330/server.crt;
    ssl_certificate_key /etc/nginx/ssl/sub.example.com/467330/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/sub.example.com/server/*;

    location /
    try_files $uri $uri/ /index.php?$query_string;


    location = /favicon.ico access_log off; log_not_found off;
    location = /robots.txt access_log off; log_not_found off;

    access_log off;
    error_log /var/log/nginx/sub.example.com-error.log error;

    error_page 404 /index.php;

    location ~ .php$
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;


    location ~ /.(?!well-known).*
    deny all;



    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/sub.example.com/after/*;


    I'd appreciate some help setting this up so that I can specify a URL to match that should not be redirected to HTTPS and then have all other URLs redirect to HTTPS.










    share|improve this question


























      0












      0








      0








      I have nginx setup to redirect all HTTP requests to HTTPS like so:



      # Redirect every request to HTTPS...
      server
      listen 80;
      listen [::]:80;

      server_name .sub.example.com;
      return 301 https://$host$request_uri;



      I have a requirement for a specific route to not be forced to HTTPS /iot/token/weather.



      I tried updating the nginx config like so:



      # Redirect every request to HTTPS...
      server
      listen 80;
      listen [::]:80;

      location ~* ^/iot/[0-9a-z]/weather$
      break;


      server_name .sub.example.com;
      return 301 https://$host$request_uri;



      However the HTTP request was still being forced to HTTPS.



      So I tried doing this:



      # Redirect every request to HTTPS...
      server
      listen 80;
      listen [::]:80;

      server_name .sub.example.com;

      location ~* ^/iot/[0-9a-z]/weather$
      break;


      location /
      return 301 https://$host$request_uri;




      However this still isn't working.



      The above is the only file imported in the before section below:



      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/sub.example.com/before/*;

      server
      listen 80;
      listen [::]:80;
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      server_name sub.example.com;
      root /home/forge/sub.example.com/public;

      # FORGE SSL (DO NOT REMOVE!)
      ssl_certificate /etc/nginx/ssl/sub.example.com/467330/server.crt;
      ssl_certificate_key /etc/nginx/ssl/sub.example.com/467330/server.key;

      ssl_protocols TLSv1.2;
      ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
      ssl_prefer_server_ciphers on;
      ssl_dhparam /etc/nginx/dhparams.pem;

      add_header X-Frame-Options "SAMEORIGIN";
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Content-Type-Options "nosniff";

      index index.html index.htm index.php;

      charset utf-8;

      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/sub.example.com/server/*;

      location /
      try_files $uri $uri/ /index.php?$query_string;


      location = /favicon.ico access_log off; log_not_found off;
      location = /robots.txt access_log off; log_not_found off;

      access_log off;
      error_log /var/log/nginx/sub.example.com-error.log error;

      error_page 404 /index.php;

      location ~ .php$
      fastcgi_split_path_info ^(.+.php)(/.+)$;
      fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;


      location ~ /.(?!well-known).*
      deny all;



      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/sub.example.com/after/*;


      I'd appreciate some help setting this up so that I can specify a URL to match that should not be redirected to HTTPS and then have all other URLs redirect to HTTPS.










      share|improve this question
















      I have nginx setup to redirect all HTTP requests to HTTPS like so:



      # Redirect every request to HTTPS...
      server
      listen 80;
      listen [::]:80;

      server_name .sub.example.com;
      return 301 https://$host$request_uri;



      I have a requirement for a specific route to not be forced to HTTPS /iot/token/weather.



      I tried updating the nginx config like so:



      # Redirect every request to HTTPS...
      server
      listen 80;
      listen [::]:80;

      location ~* ^/iot/[0-9a-z]/weather$
      break;


      server_name .sub.example.com;
      return 301 https://$host$request_uri;



      However the HTTP request was still being forced to HTTPS.



      So I tried doing this:



      # Redirect every request to HTTPS...
      server
      listen 80;
      listen [::]:80;

      server_name .sub.example.com;

      location ~* ^/iot/[0-9a-z]/weather$
      break;


      location /
      return 301 https://$host$request_uri;




      However this still isn't working.



      The above is the only file imported in the before section below:



      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/sub.example.com/before/*;

      server
      listen 80;
      listen [::]:80;
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      server_name sub.example.com;
      root /home/forge/sub.example.com/public;

      # FORGE SSL (DO NOT REMOVE!)
      ssl_certificate /etc/nginx/ssl/sub.example.com/467330/server.crt;
      ssl_certificate_key /etc/nginx/ssl/sub.example.com/467330/server.key;

      ssl_protocols TLSv1.2;
      ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
      ssl_prefer_server_ciphers on;
      ssl_dhparam /etc/nginx/dhparams.pem;

      add_header X-Frame-Options "SAMEORIGIN";
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Content-Type-Options "nosniff";

      index index.html index.htm index.php;

      charset utf-8;

      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/sub.example.com/server/*;

      location /
      try_files $uri $uri/ /index.php?$query_string;


      location = /favicon.ico access_log off; log_not_found off;
      location = /robots.txt access_log off; log_not_found off;

      access_log off;
      error_log /var/log/nginx/sub.example.com-error.log error;

      error_page 404 /index.php;

      location ~ .php$
      fastcgi_split_path_info ^(.+.php)(/.+)$;
      fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;


      location ~ /.(?!well-known).*
      deny all;



      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/sub.example.com/after/*;


      I'd appreciate some help setting this up so that I can specify a URL to match that should not be redirected to HTTPS and then have all other URLs redirect to HTTPS.







      nginx






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 1:52







      James

















      asked Mar 26 at 0:32









      JamesJames

      9,0633 gold badges41 silver badges63 bronze badges




      9,0633 gold badges41 silver badges63 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Try it:



          server 
          listen 443;

          location /
          return 301 http://$server_name$request_uri;





          server
          listen 80;

          location /iot/
          return 301 http://$server_name$request_uri;



          location /
          return 301 https://$server_name$request_uri;





          Should be separate 2 files, once for http port 80, other one for 443.






          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%2f55348265%2fnginx-disable-https-redirection-for-specific-url%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














            Try it:



            server 
            listen 443;

            location /
            return 301 http://$server_name$request_uri;





            server
            listen 80;

            location /iot/
            return 301 http://$server_name$request_uri;



            location /
            return 301 https://$server_name$request_uri;





            Should be separate 2 files, once for http port 80, other one for 443.






            share|improve this answer





























              0














              Try it:



              server 
              listen 443;

              location /
              return 301 http://$server_name$request_uri;





              server
              listen 80;

              location /iot/
              return 301 http://$server_name$request_uri;



              location /
              return 301 https://$server_name$request_uri;





              Should be separate 2 files, once for http port 80, other one for 443.






              share|improve this answer



























                0












                0








                0







                Try it:



                server 
                listen 443;

                location /
                return 301 http://$server_name$request_uri;





                server
                listen 80;

                location /iot/
                return 301 http://$server_name$request_uri;



                location /
                return 301 https://$server_name$request_uri;





                Should be separate 2 files, once for http port 80, other one for 443.






                share|improve this answer















                Try it:



                server 
                listen 443;

                location /
                return 301 http://$server_name$request_uri;





                server
                listen 80;

                location /iot/
                return 301 http://$server_name$request_uri;



                location /
                return 301 https://$server_name$request_uri;





                Should be separate 2 files, once for http port 80, other one for 443.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 26 at 2:20

























                answered Mar 26 at 2:15









                Thanh Nguyen VanThanh Nguyen Van

                1,8852 gold badges10 silver badges25 bronze badges




                1,8852 gold badges10 silver badges25 bronze badges


















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    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%2f55348265%2fnginx-disable-https-redirection-for-specific-url%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

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?