nginx1.13.9如何跨域配置server push?

发布于 2022-09-06 15:50:18 字数 1801 浏览 14 评论 0

最近nginx.1.13.9版本已经支持server push了,

Changes with nginx 1.13.9                                        20 Feb 2018

    *) Feature: HTTP/2 server push support; the "http2_push" and
       "http2_push_preload" directives.

    *) Bugfix: "header already sent" alerts might appear in logs when using
       cache; the bug had appeared in 1.9.13.

    *) Bugfix: a segmentation fault might occur in a worker process if the
       "ssl_verify_client" directive was used and no SSL certificate was
       specified in a virtual server.

    *) Bugfix: in the ngx_http_v2_module.

    *) Bugfix: in the ngx_http_dav_module.

具体指令部分语法:

Syntax:    http2_push uri | off;
Default:    
http2_push off;
Context:    http, server, location
This directive appeared in version 1.13.9.

Pre-emptively sends (pushes) a request to the specified uri along with the response to the original request. Only relative URIs with absolute path will be processed, for example:

http2_push /static/css/main.css;
The uri value can contain variables.

Several http2_push directives can be specified on the same configuration level. The off parameter cancels the effect of the http2_push directives inherited from the previous configuration level.

Syntax:    http2_push_preload on | off;
Default:    
http2_push_preload off;
Context:    http, server, location
This directive appeared in version 1.13.9.

Enables automatic conversion of preload links specified in the “Link” response header fields into push requests.

如果是使用第一种方法。那么要求推送的资源必须是绝对路径,这个绝对路径是相对当前domain的,比如当前的页面是www.example.com,我要推送的资源是 www.example.com/demo.css,那么我只要在www.example.com的主机配置文件:

http2_push /demo.css;

即可了,但是,如果我要推送的是跨域的资源呢?比如,assets.example.com/demo.css
我该如何操作?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2022-09-13 15:50:18

不能,因为不同域名不能使用同一个TCP连接。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文