도움이 필요하고 ngx_http_v2_module
.
최근 추가에 관심이 있으시면 대부분의 기능을 추가 한 커밋 인 hg.nginx.org: HTTP/2: server push입니다.
그것의 사용은 비교적 간단합니다 : 노드를 프록시하는 서버에 http2_push_preload
지시문을 추가 한 다음 Link
헤더의 노드 메이크업의 사용으로합니다 (W3 사양에 설명 된대로 - https://www.w3.org/TR/preload/#server-push-http-2) 다음 nginx를 보내는의 일을 할 것입니다 서버 푸시를 나타내는 h2 프레임
예를 들어 index.html
을 제공하지만 image.svg
을 클라이언트에 푸시하는 /
끝 점이 있다고 가정합니다. 업스트림 서버를 구성하고 서버 구성의 수의 nginx에서
서버 구성에 http2_push_preload
사용 : 평소 원하는만큼
# Add an upstream server to proxy requests to.
upstream sample-http1 {
server localhost:8080;
}
server {
# Listen on port 8443 with http2 support on.
listen 8443 http2;
# Enable TLS such that we can have proper HTTP2
# support using browsers.
ssl on;
ssl_certificate certs/cert_example.com.pem;
ssl_certificate_key certs/key_example.com.pem;
# Enable support for using `Link` headers to indicate
# origin server push.
http2_push_preload on;
# Act as a reverse proxy for requests going to /proxy/*.
#
# Because we don't want to rewrite our endpoints in the
# Node app, rewrite the path such that `/proxy/lol` ends up
# as `/lol`.
location/{
proxy_pass http://sample-http1;
}
}
는 그 다음 NodeJS 응용 프로그램에서, 당신은
/
를 제공 싶지만 응답에 추가
Link
헤더를 추가 :
response.setHeader('Link', '</image.svg>; rel=preload; as=image');
PS : 그래, 당신이 그 꺾쇠 괄호를 유지하는 것; 나는 당신이 그들을 대체해야한다는 의미는 아닙니다.
그런데 방금 준 예제 (일부 디버깅 팁 포함)는 여기 https://ops.tips/blog/nginx-http2-server-push/에 작성되었습니다.
Nginx 1.9.5+는 외부 모듈을 사용하지 않고 HTTP/2를 지원합니다. –
예, 서버 푸시 없음, http2 업스트림 없음 –
솔루션을 찾았습니까? – mz3