鍍金池/ 問答/Linux  網(wǎng)絡(luò)安全/ nginx1.13.9如何跨域配置server push?

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

最近nginx.1.13.9版本已經(jīng)支持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.

如果是使用第一種方法。那么要求推送的資源必須是絕對路徑,這個絕對路徑是相對當(dāng)前domain的,比如當(dāng)前的頁面是www.example.com,我要推送的資源是 www.example.com/demo.css,那么我只要在www.example.com的主機配置文件:

http2_push /demo.css;

即可了,但是,如果我要推送的是跨域的資源呢?比如,assets.example.com/demo.css
我該如何操作?
回答
編輯回答
拽很帥

不能,因為不同域名不能使用同一個TCP連接。

2017年4月23日 03:14