【问题标题】:HTTP2 push with nginx?HTTP2 使用 nginx 推送?
【发布时间】:2018-09-06 22:08:42
【问题描述】:

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

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

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

【问题讨论】:

  • 你能把那个文件的相关内容也粘贴到这里吗?
  • 这是 http2 推送部分位置 / { root /var/www/wordpress/current;索引 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; }
  • 您能否编辑您的问题并添加此部分?如果您没有权限,请告诉我,我会添加它。
  • 请在此处添加编辑问题并添加详细信息
  • 我编辑了我的问题的朋友

标签: nginx push http2


【解决方案1】:

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

将证书添加到浏览器的信任存储区,这样您就会得到一个绿色挂锁,它应该可以开始工作了。

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

【讨论】:

    猜你喜欢
    • 2019-02-25
    • 2019-08-11
    • 2021-06-05
    • 2018-03-06
    • 2019-01-04
    • 2018-05-25
    • 2018-03-11
    • 2017-08-31
    • 2016-06-14
    相关资源
    最近更新 更多