How to configure www.site.com and site.com (http and https)

isn’t it much simplier to add 2 lines in nginx and restart it ?

i keep www as main , and redirect from another url

server {
listen 80;
return 301 https://www.site.org$request_uri;

and same for 443