[英]How can I deploy a Node HTTP/2 server to Google App Engine?
I have a regular Node(v12) http server on App Engine.我在 App Engine 上有一个常规的 Node(v12) http 服务器。 I switched to http2 with
http2.createSecureServer
.我使用
http2.createSecureServer
切换到 http2。 It works in development, but deploying to App Engine and after the server starts successfully it responds to requests with 502 bad gateway...它在开发中工作,但部署到 App Engine 并在服务器成功启动后它响应带有 502 bad gateway 的请求......
I tried to switch to http2.createServer
to not use https, and the request never receives a response (forever loading).我尝试切换到
http2.createServer
以不使用 https,并且请求从未收到响应(永远加载)。 The last log in App Engine Log Explorer for that request shows:该请求在 App Engine 日志资源管理器中的最后一次日志显示:
[error] 27#27: *2 upstream sent no valid HTTP/1.0 header
while reading response header from upstream, client:
169.254.1.1, server: _, request: "GET / HTTP/1.1",
upstream: "http://127.0.0.1:8081/"
It seems like it somehow is expecting http1, but I don't know why.似乎它以某种方式期待 http1,但我不知道为什么。 I also don't know why it's on port 8081, I have the port set to 8080.
我也不知道为什么它在端口 8081 上,我将端口设置为 8080。
After spending my day searching Google and their docs for anything on using http2 with App Engine, I'm burnt out.在花了一天的时间在 Google 和他们的文档中搜索有关在 App Engine 中使用 http2 的任何内容之后,我已经筋疲力尽了。 And, their support page says "post on Stack Overflow"..
而且,他们的支持页面上写着“在 Stack Overflow 上发帖”..
const http2 = require('http2');
const fs = require('fs');
const app = new (require('koa'))();
const logger = require('koa-logger');
const bodyParser = require('koa-bodyparser');
const json = require('koa-json');
const cors = require('@koa/cors');
const router = require('./router.js');
const { PORT, HOST, KEY, CERT } = require('./config.js');
app.use(logger());
app.use(bodyParser());
app.use(json());
app.use(cors({ exposeHeaders: 'authorization' }));
app.use(router.routes());
app.use(router.allowedMethods());
const server = http2
.createSecureServer(
{
key: fs.readFileSync(KEY),
cert: fs.readFileSync(CERT),
allowHTTP1: true
},
app.callback()
)
.listen(PORT, () => {
console.log(`Koa HTTP/2 running at https://${HOST}:${PORT}`);
});
runtime: nodejs12
service: api
handlers:
- url: /.*
script: auto
secure: always
redirect_http_response_code: 301
vpc_access_connector:
name:
env_variables:
NODE_ENV: production
PORT:8080
KEY: key.pem
CERT: cert.pem
...
If you want to use HTTP/2 and App Engine together you might consider using Load Balancing with your serverless applications.如果您想同时使用 HTTP/2 和 App Engine,您可以考虑在无服务器应用程序中使用负载平衡。 A 502 Error in Google App Engine might refer to several different possibilities.
Google App Engine 中的502 错误可能涉及多种不同的可能性。
Error message BAD_GATEWAY错误消息 BAD_GATEWAY
An error code 502 with BAD_GATEWAY
in the message usually indicates that App Engine terminated the application because it ran out of memory.消息中带有
BAD_GATEWAY
的错误代码 502 通常表示 App Engine 终止了应用程序,因为它用完了 memory。 The default App Engine flexible VM only has 1GB of memory, with only 600MB available for the application container.默认的 App Engine 灵活虚拟机只有 1GB 的 memory,只有 600MB 可用于应用程序容器。
Error code 502 or 503错误代码 502 或 503
App Engine may take a few minutes to respond successfully to requests. App Engine 可能需要几分钟才能成功响应请求。 If you send a request and get back an HTTP 502, 503, or some other server error, wait a minute and try the request again.
如果您发送请求并返回 HTTP 502、503 或其他一些服务器错误,请稍等片刻,然后重试该请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.