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?
create page rule in Cloudflare to Always use HTTPS.
more information - https://support.cloudflare.com/hc/en-us/articles/204144518-SSL-FAQ#h_999722138611548960019807