How to configure protected access to files on remote nginx with X-Accel-Redirect

I have 2 servers. First (domain.com) is a django/apache server, second (f1.domain.com) is a file server (nginx). Some files are protected and should only be allowed to be downloaded by registred users. To that end I have setup a nginx server with a

server {
        listen 80 default_server;
        server_name *.domain.com;
        access_log /home/domain/logs/access.log;
        location /files/ {
             internal;
             root /home/domain;
        }
}

and from Django I send a request via X-Accel-Redirect header, but it doesn't work. I think because the request comes from a remote server.

How can I accomplish this task?

Answers


"and from django I send a request via X-Accel-Redirect header" -- it's incorrect, the "X-Accel" header must be a part of response header from the upstream server.

As http://wiki.nginx.org/X-accel said, there must be a proxy_pass or fastcgi_pass directive to send the response header to nginx.

location /protected_files { 
    internal;
    proxy_pass http://127.0.0.2; 
}

Need Your Help

Handle argc equal to 0

c++ c argc

I recently saw something curious. In the HHVM source code, the very first 3 lines of the main() function read as follows: