使用nginx推送HTTP2?

时间:2018-03-28 09:28:36

标签: nginx push http2

我在我的虚拟机上安装了带有wordpress站点和openssl的nginx 1.13.10。我正在尝试测试http2推送。这是我的nginx conf文件:

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;
       }
    }

重新启动nginx并且没有错误。但是,当我使用Chrome调试时,没有资源被推送demo image

如果我在某处做错了,请告诉我。

1 个答案:

答案 0 :(得分:2)

It's a restriction in Chrome。如果您的SSL / TLS证书不受信任(因为我们可以看到您的SSL / TLS证书不在屏幕截图中),它会忽略推送的资源。即使您跳过粘贴HTTPS错误也是如此。同样,此类网站上的资源也无法缓存。

将证书添加到浏览器的信任存储区,以便获得绿色挂锁,它应该开始工作。

类似的问题(但使用Node而不是Nginx)here

相关问题