Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
X-Accel-Redirect Nginx configuration not working

I'm now deploying django projects on CentOS and have a problem with X-Accel-Redirect for protected file serving.

Here is my nginx.conf

server
    {
        listen 80;
        server_name example;
        index index.html index.htm index.php;
        root  /www/server/example;
        charset UTF-8;
        access_log /var/log/nginx/myproject_access.log;
        error_log /var/log/nginx/myproject_error.log;
        client_max_body_size 75M;

        location /public/ {
          root /www/wwwroot/myproject/;
        }
        location /media/ {
          root /www/wwwroot/myproject/;
          internal;
        }
        location / {
          include uwsgi_params;
          uwsgi_pass django;
        }
 ...
}

Of course, protected files are on /www/wwwroot/myproject/media.

And corresponding python view file is following.

class ProtectedView(generics.GenericAPIView):
    permission_classes = [IsAuthenticated]

    def get(self, request, id, target):        
        file_name = "1.png"
        response = HttpResponse()
        response["X-Accel-Redirect"] = "/media/{0}".format(file_name)
        response["Content-Disposition"] = "attachment; filename={0}".format(file_name)

        return response

But server returns 404 error.

And the myproject_error.log is like this.

[error] 24570#0: *5 open() "/www/server/example/media/1.png" failed (2: No such file or directory), client: 174.11.13.81, server: example, request: "GET /protected-view/ HTTP/1.1", upstream: "uwsgi://0.0.0.0:8008", host: "40.1.12.23"

Maybe location /media/ {} block is not working. What problem? I have changed the permission but not working. PS: I'm using django rest framework.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!