Nginx hack, enables range requests for the local and locally cached content in synapse without loss of mime types on non-range requests.
Most dirty part is that if range request for locally cached remote content fails, it must be back-substituted and proxied with original path, requiring another named location.
At least it doesn't require lua or database connections.
location @proxy { proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://127.0.0.1:8008; } location ~ "/_matrix/media/v3/download/example.com/([a-zA-Z]{2})([a-zA-Z]{2})([a-zA-Z]+)" { root /path/to/synapse/media_store/local_content; if ($http_range) { rewrite "/_matrix/media/v3/download/[^/]*/([a-zA-Z]{2})([a-zA-Z]{2})([a-zA-Z]+)" /$1/$2/$3 break; } try_files $uri @proxy; } location @expandproxy { rewrite /([^/]*)/([^/]*)/([^/]*)/([^/]*) /_matrix/media/v3/download/$1/$2$3$4 break; try_files $uri @proxy; } location ~ "/_matrix/media/v3/download/(?!example.com)([^/]*)/([a-zA-Z]{2})([a-zA-Z]{2})([a-zA-Z]+)" { root /path/to/synapse/media_store/remote_content; if ($http_range) { rewrite "/_matrix/media/v3/download/([^/]*)/([a-zA-Z]{2})([a-zA-Z]{2})([a-zA-Z]+)" /$1/$2/$3/$4 break; } try_files $uri @proxy; error_page 404 = @expandproxy; }