Nginx检查多个根 [英] Nginx check multiple roots

查看:57
本文介绍了Nginx检查多个根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在nginx配置中有一个位置:

I have a location in my nginx configuration :

   location ~ \.(js|jpg|png|css|gif|ico|svg|jpeg)$ {
            root /some/basic/root;
       }

它适用于一个目录/some/basic/root中的静态文件.但是我在其他目录中还有其他一些静态文件,例如cssjs:

It works for static files in one directory /some/basic/root. But I have some other static files like css and js in other directories :

root /completely/other/root;

root /completely/other/root/dir1;

root /completely/other/root/dir2;

如何使nginx也检查其他目录?

How to make nginx check also other directories?

推荐答案

如果存在公共的父目录,则可以使用try_files依次测试每个子目录:

If there is a common parent directory, you can use try_files to test each subdirectory in turn:

location ~ \.(js|css)$ {
    root /common/parent;
    try_files /basic/root$uri /other/root$uri /other/root/dir1$uri /other/root/dir2$uri =404;
}

如果公共父目录不可行,则可以再次使用try_files来级联location块:

If a common parent directory is not practical, you can cascade location blocks, again using try_files:

location ~ \.(js|css)$ {
    root /some/basic/root;
    try_files $uri @other;
}
location @other {
    root /completely/other/root;
    try_files $uri /dir1$uri /dir2$uri =404;
}

有关详细信息,请参见此文档.

See this document for details.

这篇关于Nginx检查多个根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆