node.js - 如何在 443 中为 apache 和 Node 配置 https 支持?

标签 node.js apache ssl https reverse-proxy

实际状态:

http://www.example.com/mypage apache http:好的!
https://www.example.com/mypage apache https:好的!

http://www.example.com:8000 Node http:好的!
https://www.example.com:8000 Node https:不工作(仍然)

我尝试修改 Node 程序为

var express = require('express');
var app = express();
var https = require('https');
var fs = require('fs');

var server = http.createServer(app);

https.createServer({ 
        key: fs.readFileSync("/etc/letsencrypt/live/www.example.com/privkey.pem"),
        cert: fs.readFileSync("/etc/letsencrypt/live/www.example.com/fullchain.pem"),
        ca: fs.readFileSync("/etc/letsencrypt/live/www.example.com/chain.pem")
}, app).listen(443);

这里明显的问题是apache已经在监听443端口了

Error: listen EADDRINUSE :::443

有没有办法使用 Apache 443 为 Node 提供 SSL?

最佳答案

您只能将一个进程绑定(bind)到服务器上的给定端口。

就是说,正确的方法是让 Apache 监听 443,然后使用 mod_proxy 在 HTTP 端口(不是 w/SSL,但你仅在本地主机上交谈)或在 unix 套接字上交谈。

关于如何使用端口 80/HTTP 执行此操作的一个很好的示例如下:http://blog.podrezo.com/making-node-js-work-with-apache/

<VirtualHost *:80>
  ServerName pastebin.mydomain.com
  ServerAlias www.pastebin.mydomain.com
  DocumentRoot /var/www/pastebinjs/
  Options -Indexes
  ErrorDocument 503 /maintenance.html

  ProxyRequests on
  ProxyPass /maintenance.html !
  ProxyPass / http://localhost:8000/
</VirtualHost>

但如果您将 Proxy* 行添加到现有 HTTPS 端点,则理论是相同的。

关于node.js - 如何在 443 中为 apache 和 Node 配置 https 支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48429059/

相关文章:

SSL 安全问题

java - 需要帮助使用证书文件运行 Spring restTemplate - 无法找到请求目标的有效证书路径

node.js - 如何在 postgresql 和 node js 中进行类似搜索

json - 使用 Express 4 在 Node.js 中解析 JSON 发布请求

node.js - 如何 - AWS Rest API 身份验证

linux - 在 Linux 上检查所有文件和文件夹所有者/组和权限的任何命令

java - 将 groovy 的 RestClient 与 ignoreSSLIssues() 一起使用时出现 SSLPeerUnverifiedException :"peer not authenticated"

node.js - nodejs覆盖模块中的函数

将数据插入数据库的 PHP 脚本在执行时返回成功,但记录未插入数据库?

php - 随机排序的多次搜索的性能