0

I am having an issues with trying to serve content from a subfolder of my Nginx 1.9.15 install, which is running on MacOS X 10.11. The configuration in my nginx.conf is (there is no other root entry):

location / {
    root /Library/WebServer/Documents;
    index  index.html index.htm;
}

location /media {
    root /Library/WebServer/media;
    mp4;
    mp4_buffer_size       1m;
    mp4_max_buffer_size   5m;
}

When I request http://localhost/media/myvideo.mp4, I get in the nginx error.log:

"/Library/WebServer/media/media/myvideo.mp4" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /media/myvideo.mp4 HTTP/1.1", host: "localhost"

I can't quite understand why the 'media' entry is being duplicated. My expectation is that it should be serving /Library/WebServer/media/myvideo.mp4.

Can anyone suggest what could be wrong?

5
  • '/Library/' and 'Library/' are not the same thing (you're missing the first slash under /media). Also, I don't see any 'duplication' here. What do you mean by that?
    – user143703
    May 16, 2016 at 19:41
  • If you want it to serve /opt/local/Library why have you not specified that?
    – Tim
    May 16, 2016 at 19:46
  • Even with the '/' added in front of the Library (have updated example) I get /Library/WebServer/media/media/myvideo.mp4 rather than /Library/WebServer/media/myvideo.mp4?
    – Andre M
    May 16, 2016 at 19:53
  • Because that's what you asked for! May 16, 2016 at 20:14
  • 2
    I am coming from the Apache httpd world, where there is a direct mapping between specified alias and actual path, with the alias not needing to existing in any naming sense in the subfolder.
    – Andre M
    May 19, 2016 at 17:22

1 Answer 1

1

Try this

location /media {
  root /Library/WebServer;
  mp4;
  mp4_buffer_size       1m;
  mp4_max_buffer_size   5m;
}
5
  • Could you add some notes as to why this works and the OP's config doesn't?
    – Flup
    May 17, 2016 at 10:26
  • I don't know for sure that it does work, but it should. The reason it should work is the OP has the /media/ path in their URL request and in the location configuration, which is why it's appearing twice as per their OP's comment on their post.
    – Tim
    May 17, 2016 at 19:53
  • It does work, but it bothers me since this means the location needs to match the name of the subfolder, which is not always what is wanted. Is there a solution for where I want /media, but the storage location is /Library/WebServer/videos, for example?
    – Andre M
    May 19, 2016 at 17:20
  • No the location name doesn't need to match the folder name. Look more carefully, think harder, experiment. Just make the location whatever you want it to be in the browser, the root specifies the folder, they're independent.
    – Tim
    May 19, 2016 at 19:07
  • Just to add for future reference, there are two directives to consider, based on need: root and alias. See: stackoverflow.com/questions/10631933/…
    – Andre M
    Jun 6, 2016 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .