cd /etc/nginx/
vi nginx.conf
Edit the following configuration into it, just like below:
http {
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
}
}
Save and close it.
Finally, apply configuriton:nginx -s reload