HTTP2 push with nginx?

有些话、适合烂在心里 提交于 2019-12-24 14:18:32

问题


I install nginx 1.13.10 with a wordpress site and openssl on my virtual machine. I'm trying to test http2 push. Here is my nginx conf file:

pastebin.com/71ziXeRh

   server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  192.168.133.21;
        return 302 https://$server_name$request_uri;
}
        # Load configuration files for the default server block.
    server {
        listen          443 ssl http2;
        server_name     192.168.133.21;
        include         conf.d/self-signed.conf; #ssl config
        ssl on;
        location / {
                root /var/www/wordpress/current;
                index index.php index.html index.htm;
                http2_push /wp-content/themes/twentyseventeen/assets/images/header.jpg;
                http2_push /wp-content/themes/twentyseventeen/style.css?ver=4.7.4;
        }

        error_page 404 /404.html;
            location = /40x.html {
                root /usr/share/nginx/html;
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                root                    /var/www/wordpress/current;
                try_files               $uri =404;
                fastcgi_pass            127.0.0.1:9000;
                fastcgi_index           index.php;
                fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include                 fastcgi_params;
       }
    }

Restart nginx and no error. But when I debug it with Chrome no resource was pushed demo image

Please tell me if I do something wrong somewhere.


回答1:


It's a restriction in Chrome. If your SSL/TLS cert is not trusted (as we can see yours is not in the screenshot) it ignores pushed resources. Even if you skip paste the HTTPS error. Similarly resources on such a site cannot be cached.

Add the certificate to your browser's trust store so you get a green padlock and it should start to work.

Similar question (but using Node rather than Nginx) here.



来源:https://stackoverflow.com/questions/49530846/http2-push-with-nginx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!