Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Should I not be reading the file with open(),</p> </blockquote> <p>That's correct. Your script shouldn't be opening the file. You just tell Nginx where the file exists and let it open the file and serve it.</p> <p>I believe you want to just return an empty response after setting the appropriate headers</p> <pre><code>return HttpResponse('', mimetype=contenttype) </code></pre> <p>In PHP I setup the Nginx accel redirect by doing:</p> <pre><code>//Set content type and caching headers //... header("X-Accel-Redirect: ".$filenameToProxy); exit(0); </code></pre> <p>i.e. exiting immediately after setting the header.</p> <p>For the continuing 404 problem, you've probably got an error in the Nginx conf, but you need to post the rest to be sure. Your external URL appears to be something like:</p> <pre><code>static_files/downloads/protected-test/(?P&lt;filename&gt;.+)$ </code></pre> <p>This will be matched on:</p> <pre><code>location ~ ^.*/protected-test/ { alias /&lt;path-to-my-protected-files-on-server&gt;/; internal; } </code></pre> <p>giving the 404.</p> <p>There is no need (and it's quite confusing) to have the same word <code>protected-test</code> in both the external URL and internal URL. I'd recommend not doing that i.e. have the external URL be like:</p> <pre><code>/static_files/downloads/(?P&lt;filename&gt;.+)$ </code></pre> <p>Then have the internal location block be:</p> <pre><code>location ~ ^/protected-test { alias /&lt;path-to-my-protected-files-on-server&gt;; internal; } </code></pre> <p>And then when you setup the x-accel-redirect header, swap between the two:</p> <pre><code>external_path = "/static_files/downloads"; nginx_path = "/protected-test"; filenameToProxy = str_replace(external_path, nginx_path, full_path); header("X-Accel-Redirect: ".$filenameToProxy); </code></pre> <p>Rather than having the word <code>protected-test</code> be on both sides of the request.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload