Configuring nginx to automatically redirect http to https

You can refer to the following configuration:

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