首页 > 解决方案 > 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时:

但是,我通过删除 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 ?

标签: google-chromenginxoperahttp2

解决方案


推荐阅读