子文件夹中的Nginx资产

Nick_K

我不知道是否有更好的方法在nginx的定义资产路径。例如,我希望nginx在子文件夹中提供资产。现在,我使用这个技术,它看起来不是很干了。

location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
}

location ^~ /assets/downloads {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
}

您能为资产文件夹中的文件夹提出更好的建议吗?先感谢您。

劳伦斯·基南

您的配置几乎是正确的(对于您要实现的目标)。由于我没有完整的配置,因此我想一个解决方案:

location ^~ /assets/ {
    alias /absolute/path/to/assets/;
    gzip_static on;
    expires max;
    add_header Cache-Control public;
}

注意该alias指令(以及绝对路径上的尾部斜杠)。这告诉NGINX采取URI和递归资产目录(子文件夹中搜索)。它类似于使用roottry_files服务内容时。对于之间的差异rootalias,看到这个链接

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章