Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

node.js - Hosting HTTPS nodejs server on Apache server

I have a nodejs app hosted on WHM/cPanel that uses it's own SSL certificate. Set up:

app.all('*', function (req, res) {
    res.redirect('https://' + req.headers.host + req.url);
})

let server = http.createServer(app);
server.listen(port);

const httpsServer = https.createServer(sslFiles, app);
httpsServer.listen(443, () => {
    console.log("started")
});

When starting the server up I get the error:

Error: bind EADDRINUSE null:443

There is only one other service running on port 443 which is httpd, I have amended the virtual hosts with a pre-include of:

<VirtualHost 123.4.567.890:443>
    ServerName website.co.uk
    ServerAlias www.website.co.uk
    DocumentRoot /root/public_html/

    ErrorLog /root/logs/vherror.log

    SSLProxyEngine On
    ProxyPass / https://123.4.567.890:3000
    ProxyPassReverse / https://123.4.567.890:3000
    ProxyPreserveHost On    

    SSLEngine on
    SSLProxyEngine On
    SSLUseStapling Off
    SSLCertificateFile /root/etc/website.co.uk/ssl/cert.crt
    SSLCertificateKeyFile /root/etc/website.co.uk/ssl/theKey.key
</VirtualHost>

This pre-include worked for about 2 weeks and fixed the error but suddenly it has stopped working and I am receiving the port error again and I can't for the life of me figure out why. I'm thinking it might be due to Cloudflare since I've set that up today, but I've turned all Cloudflare settings to DNS only and I still receive the error.

Thanks

question from:https://stackoverflow.com/questions/65872020/hosting-https-nodejs-server-on-apache-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Changed the vhost file proxypass and proxypassreverse to use website name instead of IP and then changed the SSL port used on nodejs server to 4433 and it seems to be working fine now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...