Answer the question
In order to leave comments, you need to log in
How to make NGINX work with multiple directories of static files?
There are two directories /test/app/dist/images and /test/vendor/static .
Both can contain static files. If the image URL contains the "/static" segment, then nginx should look for such an image in the /test/vendor/static directory , and if the URL just ends with .jpg, .png, etc., then nginx should look for such a file in the /test/ directory app/dist/images .
I wrote this config:
server {
listen *:12901;
server_name test.lan;
location / {
proxy_pass http://lan_nodes;
//....
}
location ~* /static/*\.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs|json) {
root /test/app/dist/images;
expires 10d;
}
location ~* \.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs|json)$ {
root /test/vendor/static;
expires 10d;
}
}
Answer the question
In order to leave comments, you need to log in
server {
listen *:12901;
server_name test.lan;
location / {
proxy_pass http://lan_nodes;
//....
}
location ~ ^/static/.*\.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs|json)$ {
root /test/vendor;
expires 10d;
}
location ~ \.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs|json)$ {
root /test/app/dist/images;
expires 10d;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question