【问题标题】:Is there a way to write regex for http2_push in nginx conf?有没有办法在 nginx conf 中为 http2_push 编写正则表达式?
【发布时间】:2021-07-21 14:51:12
【问题描述】:

我想 Nginx 需要 http_push 文件的绝对路径。但是每次构建后我的静态文件名都会更改。那么,我可以添加一些正则表达式来让 Nginx 推送所有 jpeg、css 等吗? 我试过这个:

    location /index.html {
       try_files $uri /index.html;
       http2_push `/*.jpeg`;
    }

但是 Nginx 说:非绝对路径“/*.jpeg

【问题讨论】:

    标签: nginx http2


    【解决方案1】:

    不,这是不可能的。既不是正则表达式,也不是 glob 模式又名通配符(你的问题基本上是)。

    但是,如果您代理(或通过 fastcgi 等从后端获取响应),您可以通过设置 http2_push_preload on; 并添加多个 Link 预加载标头来响应相应的匹配(或 glob 模式)来动态执行需要。
    详情请见Automatically Pushing Resources to Clients

    【讨论】:

    • 不幸的是,Nginx 自己提供静态数据。谢谢你的回答。
    猜你喜欢
    • 2010-10-31
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2019-02-24
    • 2019-06-28
    相关资源
    最近更新 更多