用nginx进行HTTP2推送? [英] HTTP2 push with nginx?

查看:92
本文介绍了用nginx进行HTTP2推送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

重新启动nginx,没有错误.但是,当我使用Chrome调试时,没有资源被推送演示图片

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.

推荐答案

这是Chrome的限制.如果您的SSL/TLS证书不受信任(我们可以看到您的SSL/TLS证书不在屏幕截图中),它将忽略推送的资源.即使您跳过粘贴HTTPS错误.同样,此类网站上的资源也无法缓存.

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.

类似的问题(但使用Node而不是Nginx)这里.

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

这篇关于用nginx进行HTTP2推送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆