Hi bibica,
I'm using sub_filter in Nginx all the time, I don't really know what happend in your case that you're getting an error. Try this way inserting it after the "index" line:
sub_filter_once off;
sub_filter_last_modified on;
sub_filter https://domain.com/wp-content/uploads https://cdn.domain.com/wp-content/uploads;
Please, tell me if it works for you.
Regards.