If you want a "pure" Nginx solution without writing separate cron jobs, you can use the Nginx Perl module. This allows you to execute code immediately after a request is completed.
💡 If these files are very small, consider generating them on the fly and streaming them directly from memory to Nginx without ever writing them to the disk. This bypasses the need for deletion entirely. If you’d like, I can help you: nginx delete file after download
Run a script every 5 minutes that deletes files older than 1 hour. Why this is better: If you want a "pure" Nginx solution without
The backend sends a response to Nginx with the X-Accel-Redirect header pointing to the file. Nginx serves the file directly to the user. nginx delete file after download