nginx - 使用 nginx 进行 HTTP2 推送?

标签 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

如果我在某个地方做错了什么,请告诉我。

最佳答案

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

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

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

关于nginx - 使用 nginx 进行 HTTP2 推送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49530846/

相关文章:

php - 如何让 CURL 正确执行 HTTP/2 请求?

java - 使用 header 和数据帧的 Jetty HTTP2 服务器

python - gunicorn 和 flask 以及 Nginx 的流媒体服务器问题

web - nginx、php-fpm 和 tilde 用户目录

linux - 如何从 nginx 站点的 URL 中删除端口号

javascript - Push 替换数组中的旧值

javascript - 排列:推送功能不起作用,JavaScript O(n*n!) 运行时

django 页面被黑了 - 如何 react ?

java - Parse.com 推送通知不起作用

c - http2 请求返回错误请求