Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda