How block access to original JPG files on WordPress with nginx

Block access to non-resized JPG files. Use it with caution.

WARNING: this will block access to all original JPGs, not only the large, resized ones. Use this with caution.

location ~ "^/files/(?:(?!.*-[0-9]{2,4}x[0-9]{2,4}).)*\.jpe?g$" {
    rewrite ^/files(.*) /wp-content/files$1 break;
allow 127.0.0.1;
    deny all;
}

location ~ "^/(?:(?!cache).*?)/(?:(?!.*-[0-9]{2,4}x[0-9]{2,4}).)*\.jpe?g$" {
allow 127.0.0.1;
allow 192.168.42.11;
deny all;
}

(Oh, by the way: this entry was written by Peter Molnar, and originally posted on petermolnar dot net.)