实际状态:
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/