1

I offer paid videos on my website which are only available to members. At the moment, I'm doing the entire authentication and video streaming through a PHP script, however it tends to use a lot of resources and I'd like to use nginx to actually serve the file. To do that, I found you have to send the X-Accel-Redirect header from your PHP script which then hands of the file serving to nginx.

However, there's one problem, the URL of the video to stream isn't being served by the same server as this site. It's coming from one of my other websites which is on a different VPS server (and domain) entirely. Regardless, I tried this simple test script:

<?php

header('X-Accel-Redirect: http://other-site.com/protected/videos/test.mp4');

But I don't know what to use in my nginx config to serve the file at http://other-site.com/protected/videos/test.mp4, while still hiding the original video URL from the user.

When I access the above test script, nginx returns a 404 Not Found and the error log has an entry like so:

open() "/var/www/site.com/web/publichttp://other-site.com/protected/videos/test.mp4" failed (2: No such file or directory)

So, nginx is obviously trying to resolve http://other-site.com/protected/videos/test.mp4 to a path in the site's document root, rather than recognising that it's a resource at another location and just "proxying" the file.

Anyone got any tips on getting this working?

John Dorean
  • 3,744
  • 9
  • 51
  • 82

2 Answers2

1

I believe you are trying to proxy that mp4. I guess the problem is in the configuration of the nginx server.

Take a look at this module:

http://wiki.nginx.org/HttpProxyModule

Alex
  • 317
  • 2
  • 16
0

Using nginx to forward static files with X-Accel-Redirect is typically done for locally hosted resources.... But I did find this, I think it is what you're looking for: Use Nginx to proxy files from remote location using X-Accel-Redirect

UltrasoundJelly
  • 1,845
  • 2
  • 18
  • 32