Ingress/Nginx 当我尝试检索图像时,NodeJS Express 多次 GET 失败
Ingress/Nginx NodeJS Express Multiple GET are failing when I try to retrieve the images
堆栈
- Kubernetes(数字海洋)
- 入口 Nginx 控制器
- React 前端(静态文件)
- NodeJS/Express 后端
在某些时候我需要加载多张图片,超过一百张,一些被检索但很多没有加载。在 chrome 控制台中,我收到以下错误:
GET https://api.mydomain.com/images/products/F10014-soporte-caja-2.501.jpg net::ERR_HTTP2_SERVER_REFUSED_STREAM
此图片位于 public express 文件夹中:
let publicPath = path.join(__dirname, '/public')
console.log(`publicPath ${publicPath}`)
我查看了 NodeJS,没有发现任何错误。我还尝试在 ingress-nginx
服务中添加注释:
apiVersion: v1
kind: Service
metadata:
annotations:
kubernetes.digitalocean.com/load-balancer-id: "e7f5dc8e-3723-11ec-8d3d-0242ac130003"
service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true"
service.beta.kubernetes.io/do-loadbalancer-hostname: "mydomain.com"
labels:
helm.sh/chart: ingress-nginx-4.1.0
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
type: LoadBalancer
externalTrafficPolicy: Local
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
- name: https
port: 443
protocol: TCP
targetPort: https
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/component: controller
我的问题是:
- 问题出在
ingress-nginx
控制器上吗?
- 这能解决吗?
- 我应该更改我的解决方案并将文件放在另一个地方吗?
如果您需要信息,请告诉我。
简而言之:
My questions are
- Is the problem in the ingress-nginx controller?
基本没有
- Can this be solved?
是
- Should I change my solution and place the files in another place?
视情况而定:)
解释:
首先,您需要确定错误的来源。您已收到来自此请求的 ERR_HTTP2_SERVER_REFUSED_STREAM
:https://api.mydomain.com/images/products/F10014-soporte-caja-2.501.jpg
。看起来您尝试一次下载太多数据并收到此错误。你如何解决这个错误?首先,您可以尝试分批下载数据,而不是一次全部下载。另一种解决方案是配置您从中下载图片的 nginx 服务器。见 documentation:
Sets the maximum number of concurrent HTTP/2 streams in a connection.
Syntax: http2_max_field_size size;
Default: http2_max_field_size 4k;
Context: http, server
你可以在这里设置更大的值。
您也可以在文件/etc/nginx/conf.d/custom_proxy_settings.conf
行
中设置更大的值
http2_max_concurrent_streams 256;
文件的确切名称并不重要,它只需要以 .conf 结尾并安装在 /etc/nginx/conf.d.
中
另一种解决方案可能是禁用 HTTP/2 并使用 HTTP/1.1 协议,但这可能存在安全风险。
您还问过:
Should I change my solution and place the files in another place?
可以,但没有必要。
堆栈
- Kubernetes(数字海洋)
- 入口 Nginx 控制器
- React 前端(静态文件)
- NodeJS/Express 后端
在某些时候我需要加载多张图片,超过一百张,一些被检索但很多没有加载。在 chrome 控制台中,我收到以下错误:
GET https://api.mydomain.com/images/products/F10014-soporte-caja-2.501.jpg net::ERR_HTTP2_SERVER_REFUSED_STREAM
此图片位于 public express 文件夹中:
let publicPath = path.join(__dirname, '/public')
console.log(`publicPath ${publicPath}`)
我查看了 NodeJS,没有发现任何错误。我还尝试在 ingress-nginx
服务中添加注释:
apiVersion: v1
kind: Service
metadata:
annotations:
kubernetes.digitalocean.com/load-balancer-id: "e7f5dc8e-3723-11ec-8d3d-0242ac130003"
service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true"
service.beta.kubernetes.io/do-loadbalancer-hostname: "mydomain.com"
labels:
helm.sh/chart: ingress-nginx-4.1.0
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
type: LoadBalancer
externalTrafficPolicy: Local
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
- name: https
port: 443
protocol: TCP
targetPort: https
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/component: controller
我的问题是:
- 问题出在
ingress-nginx
控制器上吗? - 这能解决吗?
- 我应该更改我的解决方案并将文件放在另一个地方吗?
如果您需要信息,请告诉我。
简而言之:
My questions are
- Is the problem in the ingress-nginx controller?
基本没有
- Can this be solved?
是
- Should I change my solution and place the files in another place?
视情况而定:)
解释:
首先,您需要确定错误的来源。您已收到来自此请求的 ERR_HTTP2_SERVER_REFUSED_STREAM
:https://api.mydomain.com/images/products/F10014-soporte-caja-2.501.jpg
。看起来您尝试一次下载太多数据并收到此错误。你如何解决这个错误?首先,您可以尝试分批下载数据,而不是一次全部下载。另一种解决方案是配置您从中下载图片的 nginx 服务器。见 documentation:
Sets the maximum number of concurrent HTTP/2 streams in a connection.
Syntax: http2_max_field_size size; Default: http2_max_field_size 4k; Context: http, server
你可以在这里设置更大的值。
您也可以在文件/etc/nginx/conf.d/custom_proxy_settings.conf
行
http2_max_concurrent_streams 256;
文件的确切名称并不重要,它只需要以 .conf 结尾并安装在 /etc/nginx/conf.d.
中另一种解决方案可能是禁用 HTTP/2 并使用 HTTP/1.1 协议,但这可能存在安全风险。
您还问过:
Should I change my solution and place the files in another place?
可以,但没有必要。