Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I currently have

        location /folder1 {
            configuration goes here
        }    

        location /folder2 {
            configuration goes here
        }

I want to serve .mp4 files in these two locations by using the mp4 module

location ~ \.mp4$ {
  mp4;
}

What is the proper way to do this? If I just add location ~ \.mp4$ like above, then wouldn't mp4 files lose configuration from the location folder its in?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
location /folder1 {
    folder1 config;
}    
location ~* ^/folder1/.*\.mp4$ {
    folder1 config duplicated;
    mp4;
}

location /folder2 {
    folder2 config;
}
location ~* ^/folder2/.*\.mp4$ {
    folder2 config duplicated;
    mp4;
}

nginx doesn't try to combine all of the config sections like Apache does, in order to achieve speed and simplicity. The drawback to that is that you'll need to duplicate your folder directives in the location blocks for the mp4 files.

share|improve this answer
add comment

Use nested locations:

location /folder1 {

       ...

       location ~ \.mp4$ {
             mp4;
       }
}
share|improve this answer
    
The nginx documentation said nested locations might not be a good idea –  Matthew Hui Dec 2 '11 at 7:49
    
    
The result is the same as Shane Madden's answer right? –  Matthew Hui Dec 2 '11 at 9:15
    
Yes, result will be the same, but that configuration will affect the performance. A little bit :) –  Vadim Dec 2 '11 at 10:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.