nginxhttp-redirecthttpswebservercloudflare

307 Temporary Redirect not work nginx 1.18


I deployed apirest and others service need it login.... last days work fine because i did use http, today install https and all request post/get work fine with https but y i try it call same endpoint redirect not work.

My objective is call transparent way when use http://.... or https://...

i researched about this case and all ppl talk about 307/308 but not work for me

nginx - sites-enabled/default

server {
 listen 80;
 listen [::]:80;

 server_name mydomain.com;     
 return 307 https://$server_name$request_uri;
}

in this case i tried it with 307 and 308 but not work i see that access.log, nginx redirect url with method GET when my request is with POST

pls any idea?


Solution

  • i can fixed this problem....

    I tried diversitieds config in cloudflare... and i detected that they modified all request when the field Always Use HTTPS is active, in menu SSL/TLS > Edge Certificate

    Always Use HTTPS
    Redirect all requests with scheme “http” to “https”. This applies to all http requests to the zone.
    

    and only desctivated this option

    also, i confirmated that return 308 work fine with this config:

    server {
      listen 80; ssl off;
      listen 443 ssl;
      listen [::]:443 ssl;
      include snippets/self-signed.conf;
      include snippets/ssl-params.conf;
    
      root /var/www/public;
    
      index index.php index.html index.htm index.nginx-debian.html;
    
      server_name api.mydomain.com;
    
      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt  { access_log off; log_not_found off; }
      location / {
        if ($scheme = "http") {            
            return 308 https://$server_name$request_uri;
        }
        autoindex on;
        try_files $uri $uri/ /index.php?$args;
      }
    .
    .
    .
    }
    

    #Update 05/07/2022

    I detected other problem related when i activated http/https in other server and the domian is administrated by Cloudflare

    i needed activated the check "Proxied" in "DNS Management" because i had a problem in an application with vb.net