简体   繁体   中英

443 apache SSL Port and 8888 https listening Port doesn't work - Node.js - socket.io

currently i have the following problem:

i have an apache server, running SSL on Port 443 and standard (http) on 80. Additionally a installed a Node.js server with socket.io module.

I wrote an socket.io javascript with a http server that listened to the port 3000, so in the client (browser) i include the socket.io.js like this

<script type="text/javascript" src="http://www.example.com:3000/socket.io/socket.io.js"></script>

This works very fine, when i execute my site via http://www.example.com . The browser finds the socket.io.js properly.

If i execute my site via https like https://www.example.com , i adjust the script part above like this:

<script type="text/javascript" src="https://www.example.com:8888/socket.io/socket.io.js"></script>

I changed the src to https:// and the port to 8888 . Now i have to adapt my socket.io script also.

var https = require('https');
    var fs = require('fs');
    var socketio = require('socket.io');

    // The server options
    var svrPort = 8888; // This is the port of service

var svrOptions  = {
    key:    fs.readFileSync('/path/to/example.key'),
    cert:   fs.readFileSync('/path/to/example-ca.crt'),
    ca:     fs.readFileSync('/path/to/example-server.pem')
};

    // Create a Basic server and response
    var servidor = https.createServer( svrOptions , function( req , res ){
    res.writeHead(200);
    res.end('Hi! Code here...');
    });

    // Create the Socket.io Server over the HTTPS Server
    io = socketio.listen( servidor );

    // Now listen in the specified Port
    servidor.listen( svrPort );

If i execute the file with node, the socket.io started properly:

info  - socket.io started

But here comes the problem: if i execute the URL of the socket.io.js file in the browser, nothing happens:

https://www.example.com:8888/socket.io/socket.io.js

Firefox answers with: data communication interrupted

The node server also gets no requests. socket.io doesn't react.

What i have to do?

Thx!

There are two js scripts needed here, one for the node.js server (I assume that is the one you posted) and one embedded in the html page.

The <source> Tag has nothing to do with the execution of your node.js server script. It states where the client will download the client js script, when loading your HTML page. It therefore needs to be downloadable from your browser - just try entering that URL yourself.

The address, where the client side of the socket.io code is receiving its content (the address of the node.js Server) must be updated in the client side js.

Depending on the size of your project, why not also use node.js as the only server for the static content?

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