Thursday, March 31, 2016

Re: Django + Nginx + X-Accel-Redirect

Try changing file_url to be relative: 

file_url = '/media/users/avatar.png'

Also check the nginx error log to make sure the path is being constructed properly by nginx.


From: "Neto" <paulosouzamaciel@gmail.com>
To: "Django users" <django-users@googlegroups.com>
Sent: Thursday, March 31, 2016 11:04:07 AM
Subject: Django + Nginx + X-Accel-Redirect

How do I access protected directories using Django? I have the following configuration but is not working, there is always page 404 when I try to access the directory.

Django:

def test(request):
    file_url
= 'http://mysite.com/media/users/avatar.png'
    response
= HttpResponse()
    response
['X-Accel-Redirect'] = file_url
   
return response

Nginx:

server {
    listen
80;
    server_name mysite
.com;

    location
/media/ {
       
internal;
       
alias /home/ubuntu/webapps/myapp/media/;
   
}
}



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c965f092-bf02-4146-8a5f-2e5f7fef90db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment