I'm trying to add authentication to allow only valid users to download static files from nginx.
This is my Nginx configuration :
location ^~ /download-logs {
internal;
alias media/logs;
}
And in Django I've added a route to handle the response :
url : url(r'^media/', views.protectedMedia, name="protect_media"),
views :
def protectedMedia(request):
response = HttpResponse(status=200)
response['Content-Type'] = ''
response['X-Accel-Redirect'] = '/download-logs/log.txt'
return response
When i try to go to the route http://my_ip_address/media/
from the response i can see X accel redirect field, but file is not getting downloaded
This issue is solved, basically i forgot to pass the proxy for my uwsgi server in nginx configuration...
location /api {
proxy_pass http://127.0.0.1:8000/api;
}
Hopefully this helps.
Here are the complete steps which I've followed: