Actual state:
http://www.example.com/mypage apache http: OK!
https://www.example.com/mypage apache https: OK!
http://www.example.com:8000 node http: OK!
https://www.example.com:8000 node https: Not working (still)
I've tried to modify node program to be
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);
The obvious problem here is that apache is ALREADY listenning to port 443, then
Error: listen EADDRINUSE :::443
Is there a way to use Apache 443 to serve SSL for node?
You can only bind one process to a given port on your server.
That said, the correct way to do this is to have Apache listen on 443, then use mod_proxy to forward the traffic to nodejs either on an HTTP port (not w/ SSL, but you're only talking across localhost) or on a unix socket.
A good example of how to do that with port 80/HTTP is here: 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>
But the theory is the same if you add the Proxy* lines to your existing HTTPS endpoint.
Your node HTTPS server can run on any port - let's say 9090 instead of the 443 you have set. Use Apache to redirect any traffic that comes in https://example.com to your node https server listening on 9090.
Check out apache reverse-proxy for more information on how to set this up :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With