如果文件不存在,有没有办法app-*.js
在其他文件夹中服务器另一个文件,例如:
转到网址:http ://www.example.com/assets/build/app/app-48fee50a26.js
我收到以下错误消息:
[error] 17788#17788: *1 open() "/var/app/assets/build/app/app-48fee50a26.js" failed (2: No such file or directory), client: , server: , request: "GET /assets/build/app/app-48fee50a26.js HTTP/1.1", host:""
我想在同一文件夹中提供任何其他 js 文件/var/app/assets/build/app/
,但其他文件的名称可以不断更改,例如app-62a5962b0a11.js
. 我在想app\-(.*)\.js
。
以下所有示例均无效:
server {
listen 80 default_server;
root /var/app;
location /assets/build/app/app\-(.*)\.js {
try_files $uri $uri/ /assets/build/app/app\-(.*)\.js;
}
}
server {
listen 80 default_server;
root /var/app;
location /assets/build/app/app\-(.*)\.js {
try_files $uri $uri/ /var/app/assets/build/app/app\-(.*)\.js;
}
}
Also not working without regex to the location of the other file.
server {
listen 80 default_server;
root /var/app;
location /assets/build/app/app\-(.*)\.js {
try_files $uri $uri/ /var/app/assets/build/app/app-62a5962b0a11.js;
}
}
server {
listen 80 default_server;
root /var/app;
location /assets/build/app/app\-(.*)\.js {
try_files $uri $uri/ /assets/build/app/app-62a5962b0a11.js;
}
}
您的
location
指令语法错误。如果要指定正则表达式,则必须使用~
or~*
修饰符。有关详细信息,请参阅此文档。此外,您不能指望
nginx
寻找与模式匹配的随机文件。这意味着您的最后一次尝试最接近有效的解决方案。例如:我添加了作为默认术语,以避免在不存在
=404
的情况下生成循环。app-62a5962b0a11.js
但总的来说,app-62a5962b0a11.js
必须存在才能正常运行。有关语法,请参阅此文档。try_files