nginx.serve - Serve internal files
- nginx.serve.serve_media_file(file_url: str) HttpResponse
Create a response that allows a client to download a media file.
In development, the development server serves media files directly, so a re-direct to the file’s URL is returned.
In production, NGINX is used, and it serves media files. The media URL is locked down with an “internal” directive, and NGINX must receive an X-Accel-Redirect from the application to tell it that it’s OK to serve the file.
For more info, see: NGINX docs
Note
This function does not do any permission checking. Make sure the client that is asking for a file has the proper permission before calling this function.
- Parameters:
file_url – The media URL to serve
- Returns:
Direct redirect in development (DEBUG) mode, X-Accel-Redirect in production
- Return type:
HttpResponse