Reputation: 1579
I am trying to implement http2_push
using nginx
on windows 7. I followed steps mentioned in this article.
I'm running nginx 1.13.12
executable version. Have created & installed self signed certificates and it is working fine.
As mentioned in this answer, I checked and solved the certificate validation issue as well.
Still the files I want to push is not getting pushed into the browser. I am checking it through the network tab in inspector (Google Chrome - Screenshot attached).
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 443 ssl http2;
server_name localhost;
ssl_certificate ssl/localhost.crt;
ssl_certificate_key ssl/localhost.key;
location = /test.html {
root html;
http2_push /stylepush.css;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Output (Screenshot):
Can anyone help me out where I am going wrong? Thanks for the help in advance.
Upvotes: 0
Views: 886
Reputation: 45940
HTTP/2 push only works when the pushed resource is needed by the page (i.e. it's referenced in the HTML). In this case, the fact that /stylepush.css
is not loaded by the page at all (never mind by Push as the initiator) shows it is not being used.
If you go to chrome://net-internals/#http2
you should see this as an unclaimed push:
Add a reference to this CSS file in your HTML and you should see it as pushed.
If not, then go to chrome://net-internals/#events&q=type:HTTP2_SESSION
in Chrome and provide the HTTP/2 Session data.
Additionally Chrome requires a recognised certificate before it allows you to cache resources (and HTTP/2 resources are pushed into a cache before they are uses). Since Chrome Version 58, they also require the Subject Alternative Name (SAN) to be be set on the certificate, which requires some extra config to set when creating a self-signed certificate.
Upvotes: 2