the problem is this: we have a bunch of files, pdfs say, on our webserver that we want people to download, but only if they’re registered users. everyone else gets 404
s.
there’s no shortage of ways to homeroll a solution to this issue (i often use private s3 buckets), but perhaps the most elegant way is to configure nginx
to do it for us. no vendor lock in with aws, no controller methods struggling under the weight of 50mb pdfs; just nginx
serving files.
in this post, we’re going to go over how to use the nginx
‘s X-Accel-Redirect
header with a light sprinking of php
to serve files from a restricted directory.