Create file the following file /etc/nginx/site-available/redirect_http_to_https
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
Create symbolic link in the /etc/nginx/site-enabled/ folder
sudo ln -s /etc/nginx/sites-available/redirect_http_to_https /etc/nginx/sites-enabled/
Restart Nginx
sudo systemctl restart nginx.service