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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현