0

The following RE matches "http://my.domain/video.mp4" successfully but cannot match "http://my.domain/abc/video.mp4".

    location ~ "^.+(mp4|mkv|m4a)$" {
        root /home/user/Videos;
    }

The log of Nginx reads

[05/May/2021:12:29:25 +0800] "GET /video.mp4 HTTP/1.1" status: 206, body_bytes: 1729881
[05/May/2021:12:29:46 +0800] "GET /abc/video.mp4 HTTP/1.1" status: 404, body_bytes: 555

This is wired. Actually, I want URLs under "/service1/" to be mapped to user1's directory and URLs under "/service2" to be mapped to user2's. So I write

    location ~ "^/service1/.+(mp4|mkv|m4a)$" {
        root /home/user1/Videos;
    }
    location ~ "^/service2/.+(mp4|mkv|m4a)$" {
        root /home/user2/Videos;
    }

And as the first example, this config cannot match anything.

I searched a lot on google. No answer can explain this. I want to get it to work. Thanks!

0

1 Answer 1

1

I know where the problem is. In my second config, if I require "/service1/abcd.mp4", Nginx will try to locate it at "/home/user1/Videos/service1/abcd.mp4" but actually the file is at "/home/user1/Videos/abcd.mp4". Theoretically, I can bypass it by rewrite

location ~ "^/service1/.+(mp4|mkv|m4a)$" {
    rewrite "^/service1/(.+(mp4|mkv|m4a))$" "$1"; 
    root /home/user1/Videos;
}
location ~ "^/service2/.+(mp4|mkv|m4a)$" {
    rewrite "^/service2/(.+(mp4|mkv|m4a))$" "$1"; 
    root /home/user2/Videos;
}

But this is not working. I am getting crazy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.