0

I'm using Ubuntu 22.10 I'm hosting a local website with Apache2 located in the /var/www/html folder. Within my html I'm sourcing videos that live on /media/dale/Movies - this is an external drive -

(Here's what (some) my code looks like:

div class="wrapper" <br>
h3> Die Hard 3 </h3 <br>
div id="Die Hard 3" <br>
video width="400" height="300" <br>
video src="/media/dale/Movies/Die Hard 3.mp4" controls <br>
/div> 

I've narrowed down the problem to the path of the movie. If I move the movie to reside within the html folder the movie will work just fine. I can't make the movie play if I try to source it to the external folder. I've tried changing permissions, adding / and .. to the beginning but none of that has worked so far.

Any help would be appreciated.

Thomas Ward
  • 74,764
  • 2
    Web servers rarely traverse outside of the path of the webroot. Put your files you want to serve within the web root. Also, don't go streaming or offering full movies externally on the Internet, this is illegal and considered piracy. – Thomas Ward Dec 23 '22 at 16:56
  • So I have to put them inside the webroot folder? I'm not offering movies to anyone but myself on my local network. I'm just trying to mess around with making a video on demand site. – Dale Ernst Dec 23 '22 at 17:18

1 Answers1

1

A starting / in a path, like /whatever, means that the thing referenced is found at the root, the topmost level of the hierarchy of a filesystem.

But, since a webserver is involved, this root has a slightly modified meaning:

  • /media/dale/whatever is normally interpreted (by you and the OS) as something referencing the root of the operating systems' physical filesystem.

  • But whithin the context of a (HTML) document being served by a webserver, / will mean the "public document root". It means the slash in localhost/

    And since your localhost maps to /var/www/html/ on the OS' physical filesystem, when your served document refers to /media/dale/whatever, it will end up being interpreted as /var/www/html/media/dale/whatever, which is not there.

You could either put your served files within /var/www/html/, or configure your server to serve the content of /media/dale/ instead of /var/www/html/. (In this latter case you would need to put also your index.html in /media/dale/.)

Another idea is —though I have never tried this, so I don't know if it's even possible— but you could experiment with leaving the server config and the location of the files as is, and try using a symlink to point to the file, or at the containing directory, from your normal server document root...

(In the meanwhile, I found this. So you need to enable symlinking in Apache throgh FollowSymLinks, while also applying sufficient access permissions on the target.)


Update:

I had one more idea, but this is also something that I haven't tried, so I'm not sure if feasible or not.

The Apache webserver has a feature called "virtual hosts", which makes it possible to simultaneously serve multiple locations from the filesystem — not just /var/www/html/, but further other locations as well.

Here is how:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-20-04

Now you could try a hack where you would define a new virtual host to point at /media/dale/. The relevant part of the doc starts from Step 4. I don't know whether this would be trivial to achieve or not, but I would look into it.

If this virtual host trick would be possible, then in your HTML file, you could refer to the ServerAlias value of this virtual host when you link to your media file (in the src="" attribute). It's like as if you would be pointing to another, additional, external webserver. As a result, your browser would bring together the content from two different sources: the HTML document itself would arrive out of /var/www/html/ (according to your current config, accessed from the browser as "localhost"), while the media files would arrive from the virtual host server alias. Unless I'm unaware of some gotcha, Apache should be happy to serve both of them to the browser.

Levente
  • 3,961
  • Ok, thank you this makes a lot more sense to me now. Thank you! I will definitely update in the comments how things are coming along. – Dale Ernst Dec 23 '22 at 19:19