0

I have a WordPress site hosted on nginx. I am using Cloudflare reverse proxy and SSL. I have setup so site will only open in https and even if someone uses http then it will be redirected to https version. In Cloudflare the SSL setting is Flexible

But problem is, it is not working like that and when a user opens http version then it doesn't redirect to https.

This is the setting defined in my config file.

server {
        listen xxx.xxx.xxx.xxx:80;
        listen [::]:80;
        server_name mysiteurl.com;
        return 301 https://www.mysiteurl.com$request_uri;
}

server {
        listen xxx.xxx.xxx.xxx:80;
        listen [::]:80;
        root /var/www/mysiteurl.com/html;
        index portal.php index.php  index.html index.htm;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
                fastcgi_param HTTPS on;
        }
}

What am I doing wrong?

Frank Martin
  • 741
  • 2
  • 12
  • 24
  • 1
    It is not clear what URL you are using but my guess is that it matches the second server section of your config - which has no redirect to https. Why having two sections anyway, one with a `server_name` and one without? – Steffen Ullrich Sep 10 '20 at 12:21

1 Answers1

1

create page rule in Cloudflare to Always use HTTPS.

more information - https://support.cloudflare.com/hc/en-us/articles/204144518-SSL-FAQ#h_999722138611548960019807

Martynas Saint
  • 1,221
  • 7
  • 15