I managed to do it.
If anyone is interested, the necessary directives for Shortpixel can be found here:
https://shortpixel.com/knowledge-base/article/configure-nginx-to-transparently-serve-webp-files-when-supported/
The first Shortpixel block must be added to nginx.conf
nano /etc/nginx/nginx.conf
There I placed it at the beginning of the http block:
http {
modsecurity on;
modsecurity_rules_file /etc/modsecurity.d/modsec.conf;
server_names_hash_bucket_size 128;
## MAP for WebP detection
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
##
# Basic Settings
##
I put the second Shortpixel block in the vhost config of the corresponding domain.
location ~* ^(/wp-content/.+).(png|jpe?g)$ {
set $base $1;
set $webp_uri $base$webp_suffix;
set $webp_old_uri $base.$2$webp_suffix;
set $root "<<FULL PATH OF WP-CONTENT PARENT>>";
root $root;
add_header Vary Accept;
if ( !-f $root$webp_uri ) {
add_header X_WebP_SP_Miss $root$webp_uri;
}
try_files $webp_uri $webp_old_uri $uri =404;
}
Make sure to replace <<FULL PATH OF WP-CONTENT PARENT>> with the absolute path. This can be found in the WordPress backend under Tools > Site Health > Info > Directories and Sizes.
Then I just restarted NGINX and it worked.
systemctl restart nginx.service