Read and implemented everything but not able to redirect my domain www to non-www.
If I browse without www my site is opening fine.
My Config is as follows:
nginx version: nginx/1.10.3 (Ubuntu)
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:        16.04
Codename:       xenial
My current server-block config is as follows:
server {
    listen 80;
    server_name www.example.com;
    #return 301 $scheme://example.com$request_uri;
    #return 301 http://example.com$request_uri;
    rewrite ^(.*) http://example.com$1 permanent;
}
server {
        listen 80;
        listen [::]:80;
        server_name example.com;
        root /var/www/html/;
        index index.php index.html;
}