1

We're using private files on a site which is working quite fine.

The problem is that if an author uploads private videos which have like 10 minutes length the php worker does not shut down until the viewer has stopped looking at the video.

I would like to handover the serving process to nginx after authentication to Drupal so that the worker is free again.

So long all my attempts failed.

Here the setup:

  • PHP7.1-FPM
  • Drupal 8.4.2
  • Web Folder /var/www/web
  • Private Files /var/www/private

Nginx Config for the private files which works: location ~ ^(/[a-z\-]+)?/system/files{ try_files $uri @rewrite; }

Private File path: $settings['file_private_path'] = '../private';

I tried multiple ways of telling nginx to serve the files.

  • Changed the Request and Response so that BinaryFileResponse adds this header
  • Added X-Accel-Redirect directly to the Response
  • Multiple different nginx alias / root / internal settings

Nothing works. Is there any good example for Drupal 8 and nginx?

I can only find old things for Drupal 7. I implemented this in a seperate project in Symfony and got it working, it's just the combination of Drupal, Private files, Private image styles and so on which does not work.

Any help would be appreciated.

closed as unclear what you're asking by Pierre.Vriens, mradcliffe, Shawn Conn, DRUPWAY, kenorb Dec 5 '17 at 14:40

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    There is a solution but you would have to write lua script into nginx for proper access handling which is out of scope of Drupal so I won't go into detail. But to put it briefly, you would have to replace the controller for that route with yours, that would validate access to the file and return redirect response with JWT parameter. This would be pointed to location defined in nginx which would have to validate the jwt and only then stream the file. I haven't used open resty so maybe lua jwt validation and recompilation won't be necessary...maybe there's event nginx module for jwt validation. – user21641 Nov 27 '17 at 13:34
  • This sounds really complicated for what i try to archive. Thanks for the suggestion but i'll wait for a possible different approach before i start digging into that. – yobottehg Nov 27 '17 at 13:44
  • There is no different approach for what you are trying to do. If you want to free the thread you are asking a simple solution to an edge case problem. If you look at it from a different angle, you could use Amp, Icicle or ReactPHP but I don't think Drupal has fixed the memory leaks yet for this to be a bulletproof solution. – user21641 Nov 27 '17 at 14:29
  • Tangentially related is to return partial content, but I think that the client would need to request that via Http-Range (see resumable_download module). – mradcliffe Nov 27 '17 at 18:21

Browse other questions tagged or ask your own question.