我在为通过Apache提供的HTTP2 v12.19.0/Express应用程序设置NodeJS时遇到了问题。
我启用了mod http2 & proxy_http2并安装了npm http2。
垃圾桶/www看起来如下:
var app = require('../app');
var debug = require('debug')('production:server');
var http = require('http2');
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
var server = http.createServer(app);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
return val;
}
if (port >= 0) {
return port;
}
return false;
}
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}Apache站点配置:
<VirtualHost *:443>
Protocols h2 http/1.1
ServerName domain.com
ProxyRequests On
#ProxyPass / http://localhost:3000/
#ProxyPassReverse / http://localhost:3000/
ProxyPass / h2://localhost:3000/
ProxyPassReverse / http://localhost:3000/
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>没有线条
ProxyPass / h2://localhost:3000/
ProxyPassReverse / http://localhost:3000/我得到:
代理错误 代理服务器收到来自上游服务器的无效响应。代理服务器无法处理请求。 原因:从远程服务器读取错误 domain.com端口443的Apache/2.4.41 (Ubuntu)服务器
如果我把这些台词都包括进去:
内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 请在没有提供地址的情况下与服务器管理员联系,通知他们此错误发生的时间以及您在此错误之前执行的操作。 有关此错误的详细信息,请参阅服务器错误日志。domain.com端口443的Apache/2.4.41 (Ubuntu)服务器
感谢你的帮助..。
发布于 2020-10-15 14:06:32
您正在尝试通过HTTPS (h2)通过HTTP/2连接从Apache到Node,但是从Node代码看,您使用的是TLS证书,所以我猜它只是HTTP/2 over HTTP服务器(h2c)。
因此,将这些行替换为:
ProxyPass / h2://localhost:3000/
ProxyPassReverse / http://localhost:3000/在这方面:
ProxyPass / h2c://localhost:3000/
ProxyPassReverse / http://localhost:3000/它应该通过HTTP/2连接。
不过,我会质疑这个的价值。Mod_proxy_http2是仍被标记为实验性和后端HTTP/2连接的值有很大的疑问。如果您希望在Node中使用HTTP/2进行实验,那么您不应该直接连接而不是通过Apache吗?
https://stackoverflow.com/questions/64367499
复制相似问题