There is an example in the Nginx Beginner's Guide 1 that shows how to redirect requests for certain file types to a specific location:
location ~ \.(gif|jpg|png)$ {
root /data/images;
}
Suppose I wanted to do this for a list of maybe a hundred different file extensions. It would be really ugly to write it all in that same line. Is there a way I can read the conditional argument in from a file?
External file FILE_EXTENTIONS.txt:
txt
data
jpg
mp3
midi
png
xml
csv
...
And then in my nginx.conf:
location ~ \.(open(FILE_EXTENSIONS.txt))
root /data/images;
}
The main thing is I want to be able to read from a long list inside the nginx.conf
So it turns out it is as simple as including the file at the top and the config file automatically inherited the variables/directives.
For example:
include filetype.rules;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.