【发布时间】:2021-01-29 16:44:13
【问题描述】:
我在为通过 Apache 服务器提供的 NodeJS v12.19.0/Express 应用程序设置 HTTP2 时遇到问题。
我启用了 mod http2 & proxy_http2 并安装了 npm http2。
bin/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/
我明白了:
代理错误
代理服务器收到来自上游服务器的无效响应。 代理服务器无法处理请求
原因:从远程服务器读取错误
Apache/2.4.41 (Ubuntu) 服务器位于 domain.com 端口 443
如果我包含这些行,我会得到:
内部服务器错误
服务器遇到内部错误或配置错误,并且 无法完成您的请求。
请联系 [no address given] 的服务器管理员以 告知他们此错误发生的时间,以及您采取的措施 在此错误之前执行。
有关此错误的更多信息可能在服务器错误中可用 日志。 domain.com 端口 443 上的 Apache/2.4.41 (Ubuntu) 服务器
感谢您的帮助..
【问题讨论】:
标签: node.js apache express http2