google-chrome - HTTP/2 流 1 未完全关闭:PROTOCOL_ERROR
问题描述
我的 nginx 中有这个配置:
location ~* ^/test(.*) {
add_header "Access-Control-Allow-Origin" $http_origin;
add_header "Access-Control-Allow-Credentials" "true";
# PLEASE NOT THIS ONE, IT IS SEPARATED BY NEWLINE
add_header "Access-Control-Allow-Headers" "Access-Control-Allow-Origin,Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Re
quested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,sid_internal,access_token,Referer";
add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,PATCH";
# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" $http_origin;
add_header "Access-Control-Allow-Credentials" "true";
add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,HEAD,PATCH";
# PLEASE NOT THIS ONE, IT IS SEPARATED BY NEWLINE
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept, sid_internal, access_token, R
eferer";
return 204;
}
假设服务器名称是 example.com
当我点击https://example.com/test时:
- 使用 Chrome 和 Opera 浏览器,我得到HTTP/2 流 1 没有完全关闭:PROTOCOL_ERROR
- 使用 Firefox,它工作得非常好
- 当我从我的 linux 终端卷曲时,我得到HTTP/2 流 1 没有完全关闭:PROTOCOL_ERROR
但是,我通过删除 nginx 中的换行符分隔配置进行了一些修复,所以它变成了这样:
location ~* ^/test(.*) {
add_header "Access-Control-Allow-Origin" $http_origin;
add_header "Access-Control-Allow-Credentials" "true";
# PLEASE NOTE THIS ONE, NEWLINE REMOVED
add_header "Access-Control-Allow-Headers" "Access-Control-Allow-Origin,Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,sid_internal,access_token,Referer";
add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,PATCH";
# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" $http_origin;
add_header "Access-Control-Allow-Credentials" "true";
add_header "Access-Control-Allow-Methods" "GET,POST,DELETE,OPTIONS,HEAD,PATCH";
# PLEASE NOTE THIS ONE, NEWLINE REMOVED
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept, sid_internal, access_token, Referer";
return 204;
}
更改 nginx 配置后,一切正常(在 chrome、opera 和我的 linux 终端中)
好吧,我的问题实际上已经解决了。
但只是想知道,任何人都知道为什么第一个 nginx 配置(带有换行符的那个)会导致 PROTOCOL_ERROR ?
解决方案
推荐阅读
- c++ - 如何使用 Cygwin 在 Windows 上使用 Linux 头文件?
- ios - Flutter:iOS 应用的应用跟踪透明度
- java - 带有自定义控制器的 JavaFX 自定义组件
- python - Pytorch Data Loader 将图像连接到输入图像
- react-native - Expo 和 Native Base 无法解析依赖树
- c++ - Boost graph max flow algorithm——关于反向弧的作用的问题,如果它们已经存在于原始输入图中
- git - 从大师推向开发
- python - 传奇牵牛星滑块
- path - F#获取文件内容而不提供完整路径
- swiftui - 如何使用 SwiftUI DocumentGroup 读取大文件而不制作临时副本?