我在我的网站上遇到了 ERR_HTTP2_PROTOCOL_ERROR。

huangapple go评论128阅读模式
英文:

I am facing ERR_HTTP2_PROTOCOL_ERROR on my website

问题

我网站的一些文件(如CSS和JavaScript)遇到ERR_HTTP2_PROTOCOL_ERROR问题,我尝试清除浏览器缓存,但无效,请基于Web服务器(我使用NGINX进行端口转发)给我一个解决方案。

Nginx配置:

        listen 80;
        server_name  mydomain.com;
        return 301 https://dev.mydomain.com$request_uri;
}
# SSL and Proxy Setting
server {
        listen 443 ssl;
        ssl_certificate /etc/ssl/dev.cryptojobs.com/certificate.crt;
        ssl_certificate_key /etc/ssl/dev.cryptojobs.com/private.key;

        server_name dev.mydomain.com
        access_log /var/log/nginx/dev.mydomain.com.access.log;
        error_log /var/log/nginx/dev.mydomain.com.error.log;

        location / {
                proxy_pass         http://127.0.0.1:85;
                proxy_http_version 1.1;
                proxy_set_header   Upgrade $http_upgrade;
                proxy_set_header   Connection keep-alive;
                proxy_set_header   Host $host;
                proxy_cache_bypass $http_upgrade;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_redirect off;
        }
}```

<details>
<summary>英文:</summary>

I am facing ERR_HTTP2_PROTOCOL_ERROR on my website for some of the files like CSS, and Javascript, I tried clearing the browser cache but it is not working so please do not recommend me this solution. Secondly, I can not clear the cache all the time of my all clients. Please give me a solution based on the web server, I am using NGINX with port forwarding
that is my nginx settings

Ngnix configurations:-

```server {
        listen 80;
        server_name  mydomain.com;
        return 301 https://dev.mydomain.com$request_uri;
}
# SSL and Proxy Setting
server {
        listen 443 ssl;
        ssl_certificate /etc/ssl/dev.cryptojobs.com/certificate.crt;
        ssl_certificate_key /etc/ssl/dev.cryptojobs.com/private.key;

        server_name dev.mydomain.com
        access_log /var/log/nginx/dev.mydomain.com.access.log;
        error_log /var/log/nginx/dev.mydomain.com.error.log;

        location / {
                proxy_pass         http://127.0.0.1:85;
                proxy_http_version 1.1;
                proxy_set_header   Upgrade $http_upgrade;
                proxy_set_header   Connection keep-alive;
                proxy_set_header   Host $host;
                proxy_cache_bypass $http_upgrade;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_redirect off;
        }
}```

</details>


# 答案1
**得分**: 1

我面临相同问题,通过添加```gzip```,```https2```和```proxy```设置解决了这个问题:<br><br>但是请将您的配置替换为以下内容,并重新启动您的nginx Web服务器:

server {
listen 80;
server_name dev.mydomain.com;
return 301 https://dev.mydomain.com$request_uri;

    http2_max_field_size 16k;

}

SSL和代理设置

server {
listen 443 ssl http2;
ssl_certificate /etc/ssl/dev.mydomain.com/certificate.crt;
ssl_certificate_key /etc/ssl/dev.mydomain.com/private.key;

    server_name dev.cryptojobs.com;
    access_log /var/log/nginx/dev.mydomain.com.access.log;
    error_log /var/log/nginx/dev.mydomain.com.error.log;
    # gzip off;
    gzip on;
    gzip_static on;
    gzip_comp_level 2;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_disable &quot;msie6&quot;;
    gzip_min_length 250;
    gzip_proxied no-cache no-store private expired auth;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;

    proxy_max_temp_file_size 0;
    proxy_read_timeout      3600;
    proxy_connect_timeout   300;
    proxy_redirect          off;
    # proxy_http_version 1.1;
    
    location / {
            proxy_cache off;
            proxy_pass         http://127.0.0.1:85;
            # proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_redirect off;
    }

}


<details>
<summary>英文:</summary>

I was facing the same issue and I fixed this issue by adding ```gzip```, ```https2``` and ``` proxy ``` settings: &lt;br&gt;&lt;br&gt; However replace your configuration with this and restart your nginx web server:

server {
listen 80;
server_name dev.mydomain.com;
return 301 https://dev.mydomain.com$request_uri;

    http2_max_field_size 16k;

}

SSL and Proxy Setting

server {
listen 443 ssl http2;
ssl_certificate /etc/ssl/dev.mydomain.com/certificate.crt;
ssl_certificate_key /etc/ssl/dev.mydomain.com/private.key;

    server_name dev.cryptojobs.com;
    access_log /var/log/nginx/dev.mydomain.com.access.log;
    error_log /var/log/nginx/dev.mydomain.com.error.log;
    # gzip off;
    gzip on;
    gzip_static on;
    gzip_comp_level 2;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_disable &quot;msie6&quot;;
    gzip_min_length 250;
    gzip_proxied no-cache no-store private expired auth;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;

    proxy_max_temp_file_size 0;
    proxy_read_timeout      3600;
    proxy_connect_timeout   300;
    proxy_redirect          off;
    # proxy_http_version 1.1;
    
    location / {
            proxy_cache off;
            proxy_pass         http://127.0.0.1:85;
            # proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_redirect off;
    }

}

huangapple
  • 本文由 发表于 2023年3月20日 23:09:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792026.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定