控制台报 net::ERR_HTTP2_PROTOCOL_ERROR 200

18266

问题描述

使用webman1.5.5版本建立得站点,站点首次加载是一个大白页,查看控制台出现错误,xxx/xxx.js net::ERR_HTTP2_PROTOCOL_ERROR 200。
然后第二次请求=普通刷新该页面后正常访问,强制刷新就不行。

为此你搜索到了哪些方案及不适用的原因

这个是页面在控制台输出得错误。

截图

在论坛看到有人也出现这种情况,https://www.workerman.net/q/10689 也不知道咋解决得。

我现在是把nginx压缩去掉application/javascript text/javascript这两项去掉了,然后访问也正常了。

但是我认为这应该不是最终解决办法,咨询一下大家是否有类似情况?

以下是宝塔得nginx配置文件:

user  www www;
worker_processes auto;
error_log  /www/wwwlogs/nginx_error.log  crit;
pid        /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

stream {
    log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';

    access_log /www/wwwlogs/tcp-access.log tcp_format;
    error_log /www/wwwlogs/tcp-error.log;
    include /www/server/panel/vhost/nginx/tcp/*.conf;
}

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        #include luawaf.conf;

        include proxy.conf;

        default_type  application/octet-stream;

        server_names_hash_bucket_size 512;
        client_header_buffer_size 2048k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors on;

          open_file_cache max=204800 inactive=20s;
        open_file_cache_min_uses 1;
        open_file_cache_valid 30s;

        gzip on;
        gzip_min_length 1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain  application/x-javascript text/css application/xml;
        #application/javascript text/javascript
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        limit_conn_zone $binary_remote_addr zone=perip:10m;
        limit_conn_zone $server_name zone=perserver:10m;

        server_tokens off;
        access_log off;

server
    {
        listen 888;
        server_name phpmyadmin;
        index index.html index.htm index.php;
        root  /www/server/phpmyadmin;
            location ~ /tmp/ {
                return 403;
            }

        #error_page   404   /404.html;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /www/wwwlogs/access.log;
    }
include /www/server/panel/vhost/nginx/*.conf;
}

以下是站点得配置文件:

upstream webman {
    server 127.0.0.1:8787;
    keepalive 10240;
}
server
{
    listen 80;
        listen 443 ssl http2;
    server_name xxxxxx.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/xxxxxx.com/public;

    #large_client_header_buffers 8 16k;

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    ssl_certificate    /xxxxxxxxxxxxxx/xxxxxx.com/fullchain.pem;
    ssl_certificate_key    /xxxxxxxxxxx/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers Exxxxxxxxxxxxxxxxxxxx!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;

    #SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-00.conf;
    #PHP-INFO-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/xxxxxx.com.conf;
    #REWRITE-END

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    #禁止在证书验证目录放入敏感文件
    if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
        return 403;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log /dev/null;
        access_log /dev/null;
    }

    location ~ .*\.(js|css)?$
    {
        proxy_pass http://127.0.0.1:8787;
        expires      12h;
        error_log /dev/null;
        access_log /dev/null;
    }

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_max_temp_file_size 0;
        if (!-f $request_filename){
            proxy_pass http://webman;
        }
    }
    access_log  /www/wwwlogs/xxxxxx.com.log;
    error_log  /www/wwwlogs/xxxxxx.com.error.log;
}
2698 4 1
4个回答

杨柳岸

listen 443 ssl http2; 改成 listen 443 ssl; 试试
反向代理proxy_http_version 1.1 和 webman都是http1.1的协议,正常输出不应该使用http2 应该使用http1.1
以上是根据报错的推测,没有测试

小W

看看请求文件的权限

ayhome

和你遇见了通用的问题, 不用nginx是可以的

  • 暂无评论
ayhome

暂时这样设置解决了问题

#PROXY-START/

location /
{
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'Keep-Alive';

    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    proxy_max_temp_file_size 0;
    proxy_ignore_client_abort on;

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    set $static_filebdPEJ7fN 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_filebdPEJ7fN 1;
        expires 10m;
    }
    if ( $static_filebdPEJ7fN = 0 )
    {
        add_header Cache-Control no-cache;
    }
}
#PROXY-END/

关键是
proxy_set_header Connection 'Keep-Alive';

年代过于久远,无法发表回答
×
🔝