Don’t edit /etc/nginx/sites-enabled/ because CloudPanel overwrites it. Instead, create /home/cloudpanel/htdocs/mydomain.com/nginx/custom.conf with your error_page settings, put custom-404.html in the public folder, and run systemctl reload nginx.
or
Or, alternatively, edit the vhost file in...