Nginx配置中静态位置的多个位置 [英] Multiple Location For Static Location in Nginx Configuration
问题描述
我有两个位置,我的应用将在其中提供静态文件,一个是/my/path/project/static,另一个是/my/path/project/jsutils/static.
I have a two locations where my app will serve static files, one is /my/path/project/static and the other is /my/path/project/jsutils/static.
我很难让Web服务器在两个目录中查找静态内容.这是我在应用程序的nginx配置文件中输入静态位置的信息.
I'm having a hard time getting the webserver to look in both directories for static content. Here is my entry for static location in the nginx configuration file for my app.
location ^~ /static {
root /my/path/project/static;
alias /my/path/project/jsutils/static;
index index.html index.htm;
}
我收到一条错误消息:"alias"伪指令是重复的,"root"伪指令是先前指定的.
I get an error that says : "alias" directive is duplicate, "root" directive was specified earlier.
我不确定如何使nginx在这两个路径中看起来都是静态内容.
I'm not sure how to go about having nginx look in both these paths for static content.
在此先感谢您的帮助.
推荐答案
location ^~ /static {
root /my/path/project/static;
index index.html index.htm;
try_files $uri $uri/ @secondStatic;
}
location @secondStatic {
root /my/path/project/jsutils/static;
}
因此,首先将在/my/path/project/static中搜索该文件,如果在该位置找不到该文件,则会在将根更改为/my/path/project/jsutils/static的位置触发secondStatic位置
So first the file will be searched in /my/path/project/static and if that could not be found there, the secondStatic location will be triggered where the root is changed to /my/path/project/jsutils/static.
这篇关于Nginx配置中静态位置的多个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!