在标题之前,上游连接错误或断开连接/重置。重置原因:连接终止(503)

发布于 2025-02-09 06:19:48 字数 3000 浏览 2 评论 0 原文

我试图将Hellow-World Node应用程序部署到使用WebPack(Dockerized)的 HTTP2 的云运行中,并获取上述错误。本地工作正常(并且与Docker Run命令也可以正常工作)。这是我的代码:

dockerfile

FROM node:14.15.3
WORKDIR /app
RUN npm install -y
RUN npm i -g webpack webpack-dev-server -y
RUN npm install  webpack-cli -g
COPY . /app
CMD npm run dev -y
EXPOSE 8080

webpack.config.js

var path = require('path');

module.exports = {
entry: './main.js',
mode: 'development',
devServer: {
    static: {
       directory: path.join(__dirname, "./")
    },
    historyApiFallback: true,
    host: '0.0.0.0',
    port: 8080,
    http2: true,
    server: 'spdy',
    // sockPort and disableHostCheck fix viewing over ssh tunneled ports, e.g. with gitpod.io
    allowedHosts: 'all',
    },
output: {
   path: path.resolve(__dirname, 'build'),
   filename: 'bundle.js'
}   
};

云运行日志

2022-06-20 23:56:29.624 ist

获取

503

1.21 kib

14 ms

chrome 81.0.4044.92 https://example.com/

curl结果(在云运行URL上)vibhor@vibhor:〜$ curl -i -http2-prior-knowledge https://example.com http/2 http/2 http/2 content-lengtth:95 content-type :文字/普通日期:2022年6月20日星期一 19:01:36 GMT服务器:Google前端X-Cloud-trace-context: 35984E049EE6D2C95893802984BBED3/18320099253583711577; o = 1 traceparent: 00-35984E049EE66D2C95893802984BBED3-FE3E113503C18D59-01 ALT-SVC: H3 =“:443”; MA = 2592000,H3-29 =“:443”; MA = 2592000,H3-Q050 =“:443”; MA = 2592000,H3-Q046 =“:443”; MA = 2592000,H3-Q043 =“:443”; ma = 2592000,quic =“:443”; MA = 2592000; V =“ 46,43”

上游连接错误或在标题之前断开/重置。重置 原因:连接终止

时,当我检查http2的云运行文档时()它说

您的云运行服务必须在HTTP/2 ClearText(H2C)格式中处理请求,因为TLS仍然通过云运行自动终止。

要确认您的服务支持H2C请求,请使用此curl命令在本地测试服务:

curl -I-HTTP2-PRIOR-知识https:// localhost:8080

当我本地部署并运行命令时上面给出,它说:

curl:(60)SSL证书问题:自签名证书 更多详细信息: https://curl.haxx.se/docs/docs/docs/docs/docs/ssslcerts.html

Curl无法验证服务器的合法性,因此无法建立与该服务器的安全连接。要了解有关这种情况以及如何解决的更多信息,请访问上面提到的网页。

添加到上面的命令工作中,将选项添加到上述命令工作中,

   HTTP/2 200
   x-powered-by: Express
   accept-ranges: bytes
   cache-control: public, max-age=0
   last-modified: Mon, 20 Jun 2022 03:56:22 GMT
   etag: W/"5f-1817f411ac4"
   content-type: text/html; charset=UTF-8
   content-length: 95
   vary: Accept-Encoding`enter code here` 

并对端口443进行了尝试,并且行为是相同的。还尝试在WebPack DevServer中添加 http2:true 选项,但结果是相同的

人是否可以建议我可以做的任何更改来完成此工作?

I am trying to deploy a hellow-world node app to Cloud Run using http2 with webpack (dockerized) and getting the above error. Locally it works fine (and also works fine with the docker run command). Here is my code:

Dockerfile

FROM node:14.15.3
WORKDIR /app
RUN npm install -y
RUN npm i -g webpack webpack-dev-server -y
RUN npm install  webpack-cli -g
COPY . /app
CMD npm run dev -y
EXPOSE 8080

webpack.config.js

var path = require('path');

module.exports = {
entry: './main.js',
mode: 'development',
devServer: {
    static: {
       directory: path.join(__dirname, "./")
    },
    historyApiFallback: true,
    host: '0.0.0.0',
    port: 8080,
    http2: true,
    server: 'spdy',
    // sockPort and disableHostCheck fix viewing over ssh tunneled ports, e.g. with gitpod.io
    allowedHosts: 'all',
    },
output: {
   path: path.resolve(__dirname, 'build'),
   filename: 'bundle.js'
}   
};

Cloud run log

2022-06-20 23:56:29.624 IST

GET

503

1.21 KiB

14 ms

Chrome 81.0.4044.92 https://example.com/

Curl result (on the cloud run url) vibhor@vibhor:~$ curl -i
--http2-prior-knowledge https://example.com HTTP/2 503 content-length: 95 content-type: text/plain date: Mon, 20 Jun 2022
19:01:36 GMT server: Google Frontend x-cloud-trace-context:
35984e049ee66d2c95893802984bbed3/18320099253583711577;o=1 traceparent:
00-35984e049ee66d2c95893802984bbed3-fe3e113503c18d59-01 alt-svc:
h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443";
ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443";
ma=2592000,quic=":443"; ma=2592000; v="46,43"

upstream connect error or disconnect/reset before headers. reset
reason: connection termination

When I checked the cloud run documentation for http2 (https://cloud.google.com/run/docs/configuring/http2) it says

Your Cloud Run service must handle requests in HTTP/2 cleartext (h2c) format, because TLS is still terminated automatically by Cloud Run.

To confirm that your service supports h2c requests, test the service locally using this cURL command:

curl -i --http2-prior-knowledge https://localhost:8080

When I deployed locally and ran the command given above, it says:

curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.

Adding the --insecure option to above command works and gives

   HTTP/2 200
   x-powered-by: Express
   accept-ranges: bytes
   cache-control: public, max-age=0
   last-modified: Mon, 20 Jun 2022 03:56:22 GMT
   etag: W/"5f-1817f411ac4"
   content-type: text/html; charset=UTF-8
   content-length: 95
   vary: Accept-Encoding`enter code here` 

Tried with port 443 as well and the behavior is the same. Also tried adding http2: true option to the webpack devserver but the result is the same

Could anyone suggest any changes I could do to make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文