# views.py from django.http import HttpResponse from django.views.generic import View class SendfileView(View): prefix = "" def get(self, request, path): response = HttpResponse() response["X-Accel-Redirect"] = f"{self.prefix}{path}" del response["Content-Type"] return response # urls.py from django.urls import re_path urlpatterns = [ re_path(r"^/media/(?P.*)$", SendfileView.as_view(prefix="/__media__/")) ] # nginx.conf server { server_name example.com; listen 80; location /__media__/ { internal; alias /path/to/your/media/directory/; } location / { proxy_pass http://url.to.your.django:8000; } }