简体   繁体   中英

Nodejs SSL using CloudFlare not working over https

So the problem I'm having is that the client won't connect with the server.js when the server.js is using https.

if I go to "https://mydomainame.com" I get this error in the console of every other browser than brave browser index.js:83 GET https://serverip:8081/socket.io/?EIO=3&transport=polling&t=NK0oCD6 net::ERR_CERT_AUTHORITY_INVALID 在此处输入图片说明

(The blacked out is the IP address of the server) the weird thing is that in the brave browser the domain changes to "http://mydomainame.com" and the client then is connected to server.js
在此处输入图片说明

I'm using free Cloudflare with Full end to end encryption 在此处输入图片说明

server.js code:

var express = require('express'),
https = require('https');
var app = express();
var fs = require('fs');
var httpsOptions = { 
    key: fs.readFileSync('/var/www/ssl/sitename.com.key'),
    cert: fs.readFileSync('/var/www/ssl/sitename.com.pem')};
var server = https.createServer(httpsOptions,app);
var io = require('socket.io').listen(server);

const port = 8081;
server.listen(port);

And client.js connection code:

socket = io.connect('https://serverip:8081', {secure: true});

I am using the same Origin Certificates for the server and for the nodejs code. The server is using Apache2 with PHPMyAdmin and is configured to make the domain only work using https.

I read somewhere something Cloudflare not being able to use other ports than 443 and some other but I did not really understand it, And I can't get the server.js to work over port 443.

I'm thankful for any information or help I can get! :)

So I figured it out, big thanks to Eric Wong for pointing out the biggest problem that I was trying to connect to the server using its IP there for not going thru Cloudflare.

Then in this article Identifying network ports compatible with Cloudflare's proxy you can see what ports Cloudflare allows connections on then, I have changed my code. I used the https port 8443

socket = io.connect('https://domainname.com:8443',{secure: true});

then the only thing I had to do was to port forward the new port and everything worked fine!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM