Bag*_*lid 5 google-chrome nginx cloudflare laravel http2
ERR_HTTP2_CLIENT_REFUSED_STREAM对于通过 http2 推送的全部或部分资源,我在 chrome devtools 控制台中出现以下错误。
刷新页面并随机清除缓存可以部分甚至完全解决此问题。
我正在使用启用了 http2 的 nginx(通过 certbot 进行 ssl)和 cloudflare。
server {
server_name $HOST;
root /var/www/$HOST/current/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
set $auth "dev-Server.";
if ($request_uri ~ ^/opcache-api/.*$){
set $auth off;
}
auth_basic $auth;
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~* \.(?:css|js)$ {
access_log off;
log_not_found off;
# Let laravel query strings burst the cache
expires 1M;
add_header Cache-Control "public";
# Or force cache revalidation.
# add_header Cache-Control "public, no-cache, must-revalidate";
}
location ~* \.(?:jpg|jpeg|gif|png|ico|xml|svg|webp)$ {
access_log off;
log_not_found off;
expires 6M;
add_header Cache-Control "public";
}
location ~* \.(?:woff|ttf|otf|woff2|eot)$ {
access_log off;
log_not_found off;
expires max;
add_header Cache-Control "public";
types {font/opentype otf;}
types {application/vnd.ms-fontobject eot;}
types {font/truetype ttf;}
types {application/font-woff woff;}
types {font/x-woff woff2;}
}
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/$HOST/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/$HOST/privkey.pem; # managed by Certbot
# include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = $HOST) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name $HOST;
listen 80;
return 404; # managed by Certbot
}
Run Code Online (Sandbox Code Playgroud)
谷歌搜索这个错误不会返回太多结果,如果有帮助的话,这是一个 Laravel 6 应用程序推送这些资产,如果我禁用 Laravel 中的资产推送,那么所有资产都会正确加载。
我什至不知道从哪里开始寻找。
我启用了 chrome 日志记录,并使用 Sawbuck 检查日志,按照此处提供的说明进行操作,发现实际错误与 414 HTTP 响应有一定关系,这意味着存在一些缓存问题。
我发现这很棒如果浏览器已经有推送的项目,则可以中止推送的项目,其说明如下:
如果 Chrome 推送缓存中已存在该项目,则会拒绝推送。它拒绝 with
PROTOCOL_ERROR而不是CANCELorREFUSED_STREAM。
这导致我完全禁用 cloudflare 并直接使用服务器进行测试,我尝试了各种Cache-Control指令并尝试禁用标头,但在清除缓存后刷新时会出现相同的错误。
显然,即使在推送缓存中不存在, chrome也会取消http/2推送的资源,从而导致页面损坏。
目前,我在 laravel 应用程序中禁用 http/2 服务器推送作为临时修复。
我们刚刚遇到了您所描述的完全相同的问题。我们的 Javascript 文件之一上出现了“net::ERR_HTTP2_CLIENT_REFUSED_STREAM”。重新加载和清除缓存有效,但问题又回来了,似乎是随机的。Chrome 和 Edge(基于 Chromium)中存在同样的问题。然后我在 Firefox 中尝试并得到了相同的行为,但 Firefox 抱怨该 url 的响应是“text/html”。我的猜测是,由于某种原因,我们在 Cloudflare 中得到了针对该 url 缓存的“text/html”响应。当我直接在 Firefox 中打开该网址时,我得到了“application/javascript”,然后问题就消失了。但仍然不太确定这一切是如何发生的。
编辑:在我们的例子中,事实证明 .js 文件的响应被服务器以 401 阻止,并且我们没有发送任何缓存标头。Cloudflare 试图提供帮助,因为浏览器需要一个 .js 文件,因此即使状态为 401,响应也会被缓存。后来对其他人来说却失败了,因为我们尝试将状态为 401 的 text/html 响应作为 .js 文件进行 http2 推送。幸运的是,Firefox 为我们提供了更好的、可操作的错误消息。
EDIT2:事实证明这不是 http 标头缓存问题。这是因为我们对 .js 文件进行了 cookie 身份验证,并且 http2 推送请求似乎并不总是包含 cookie。解决方法是允许对 .js 文件进行无 cookie 请求。
| 归档时间: |
|
| 查看次数: |
2667 次 |
| 最近记录: |