6

I'm trying to connect to a nodejs https server from a apache web server hosted javascript client and I'm getting an error message : 522 - Failed to load response data: No data found for resource with given indentifier. The apache web server runs on the same domain/server as the node server and the servers are proxied by Cloudflare:

Both services run in the same server/machine. This is how I start nodejs server:

// Certificates are the same used by apache web server in Virtual Host 
// and were got from Cloud Flare Panel > SSL/TLS > Origin Server
var options = {
  key: fs.readFileSync('/etc/cloudflare/example.com.key'),
  cert: fs.readFileSync('/etc/cloudflare/example.com.pem'),
};

var socket = require('socket.io');
var http = require('https');

// Port 2053 was listed as a https port supported by Cloud Flare in
// https://developers.cloudflare.com/fundamentals/get-started/reference/network-ports/
var argv = require('optimist')
    .usage('Usage: --port [num]')
    .default({port: 2053})
    .argv;

var server = http.createServer(options, function(req, res) {
});

server.listen(argv.port);

var io = socket.listen(server);

This is how I connect to nodejs server from the javascript client:

let socket = io.connect("https://www.example.com:2053", {secure: true});

Any tips?

Edit 1 It works if I create the node server as http (instead of https).

user18520267
  • 180
  • 3
  • 13
Arivan Bastos
  • 1,876
  • 1
  • 20
  • 28
  • You should use the docs on this error: https://support.cloudflare.com/hc/en-us/articles/115003011431-Troubleshooting-Cloudflare-5XX-errors Providing the domain is critical to helping you. If you cannot provide the domain, I recommend contacting Cloudflare Support directly if you have a paid plan. – Ross Jacobs Jan 30 '23 at 23:06
  • @RossJacobs thank you. I read the provided docs but I couldnt find a solution. I noticed connection works if I run the node server as http instead of https. Is there any additional steps I should take for a https connection? – Arivan Bastos Jan 31 '23 at 13:39
  • Check Flexible vs Full SSL in your settings. Do you have the origin server SSL settings that you actually need? – Ross Jacobs Feb 01 '23 at 08:29
  • @ArivanBastos What if you run the Node.js server on a port below 1024? like 444? – Mostafa Fakhraei Feb 01 '23 at 15:32

1 Answers1

0

I was able to connect to node server by doing the follow:

  1. Set "key" and "cert" options when instancing https node server: these files can be generated in Cloud Flare Panel > Select your domain > SSL/TLS > Origin Server. There was no need for "ca", "requestCert" or "rejectUnauthorized" parameters.
  2. Use one of the ports listed in https://developers.cloudflare.com/fundamentals/get-started/reference/network-ports/ in the node server. Cloud flare automatically redirect these ports to the same port in your origin server.
  3. Allow inbound connections on the selected port (step 2) in your origin server firewall.
  4. Set SSL setting to FULL in Cloud Flare Panel > Select your domain > SSL/TLS > Overview
Arivan Bastos
  • 1,876
  • 1
  • 20
  • 28