'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

  • my nginx version is 1.18
  • my domain is register in cloudflare.... i have a doubts about if this is the problem
  • restart service and restart server.... and i have same error

pls any idea?



Solution 1:[1]

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;
  }
.
.
.
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chevelle