HTTP to HTTPS Nginx too many redirects

后端 未结 3 855
闹比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 13:10

    Since you are using cloudflare flexible SSL your nginx config file wll look like this:-

    server {
      listen 80 default_server;
      listen [::]:80 default_server;
      server_name mydomain.com www.mydomain.com;
    
      if ($http_x_forwarded_proto = "http") {
          return 301 https://$server_name$request_uri;
      }
    
      root /var/www/html;
    
      index index.php index.html index.htm index.nginx-debian.html;
    
      location / {
         try_files $uri $uri/ =404;
      }
    
      location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      }
    
      location ~ /\.ht {
         deny all;
      }
    }
    

提交回复
热议问题