I use the ngx_pagespeed module for Nginx for automatic image optimization. It's really good and easy to install: https://github.com/pagespeed/ngx_pagespeed
I describe the whole setup step by step on my blog: https://blog.tjl.rocks/cheap-secure-and-fast-ghost-blog-set-...