#Insert new config
sed -i -e "0,/^#ConfHere/s/\(^#Conf.*\)/#ConfHere1 /" -e '/#ConfHere1/ r CMS_Config.txt' -e '/#ConfHere/c\' Base_Nginx_Config.txt

#Backup existing config
sed -n '/#beginConf/,/#endConf/p' Real-site > CMS_Config-Backup.txt

#Remove existing config
sed -n -i '/#beginConf/{:a;N;/#endConf/!ba;N;s/.*\n/#ConfHere1\n/};p' Base_Nginx_Config.txt

######################################
Base_Nginx_Config.txt Content  example
######################################

#generated by certbot from here
server { 
    listen       443 ssl;                       
    listen       [::]:443 ssl;                      
    server_name   www.DOMAINname;             
    return       301 http://DOMAINname$request_uri;  
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
	server_name DOMAINname;


#ConfHere

}
#generated by certbot to here


server {
    listen       80;
    listen       [::]:80;
    server_name   www.DOMAINname;
    return       301 http://DOMAINname$request_uri;
}

server {
    listen 80;
    listen [::]:80;
	server_name   DOMAINname;


#ConfHere

}

###############################
CMS_Config.txt Content example
###############################

#beginConf
    gzip on;
    gzip_proxied any;
    gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript image/svg image/svg+xml application/xml image/x-icon;
    gzip_comp_level 2;
    gzip_disable "msie6";
    gzip_buffers 16 8k;


    location / {
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;
        #try_files $uri $uri/ $uri.html $uri.php$is_args$query_string;
    }
#endConf