HTTP to HTTPS Nginx too many redirects

后端 未结 3 851
闹比i
闹比i 2021-02-02 12:24

I have a website running on a LEMP stack. I have enabled cloudflare with the website. I am using the cloudflare flexible SSL certificate for https. When i open the website in ch

3条回答
  •  清歌不尽
    2021-02-02 12:58

    I tried

    if ($http_x_forwarded_proto = "http") {
          return 301 https://$server_name$request_uri;
      }
    

    But this not allways redirected. Manually write address in browser with begining http:// and nginx not redirected. But using $scheme it's working even manually entering http:// So (for my site) is always working variant:

     if ($scheme = "http") {
          return 301 https://$server_name$request_uri;
      }
    

    P.S. sorry for my english :(

提交回复
热议问题