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

最近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
我该如何操作?
阅读 2.9k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题