totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Cluster https #686

Closed EddiDin closed 5 years ago

EddiDin commented 5 years ago

Hello. How can i start cluster on https? (I didn't find this information in docs).

petersirka commented 5 years ago

This is not possible yet. I recommend to run the cluster on HTTP and use a reverse proxy via e.g. NGINX. I think that new update will support HTTPS in cluster.

EddiDin commented 5 years ago

Thanks. I will wait for the update!

petersirka commented 5 years ago

Hi @EddiDin, I have added https into the cluster. Try it $ npm install total.js@beta and let me know.

neophylon commented 5 years ago

Hi @pertersirka I have got a error message on Chrome : ERR_SSL_VERSION_OR_CIPHER_MISMATCH my index.js // =================================================== // FOR DEVELOPMENT // Total.js - framework for Node.js platform // https://www.totaljs.com // ===================================================

const options = {}; options.ip = '0.0.0.0'; options.port = parseInt(process.argv[2]); const fs = require('fs'); options.https = { key: fs.readFileSync('/etc/letsencrypt/live/xxx.xxx.xxx/privkey.pem'), cert: fs.readFileSync('/etc/letsencrypt/live/xxx.xxx.xxx/cert.pem') }

require('total.js').cluster.https('auto', 'debug', options);

petersirka commented 5 years ago

@neophylon and does it work with:

require('total.js').https('debug', options);

?

neophylon commented 5 years ago

Sorry for late. if i use 'require('total.js').https('debug', options);', everything is fine. So, now I have used only https not cluster https. But I want to use cluster https. I installed totaljs@beta version already.

petersirka commented 5 years ago

Shit, sorry --> my bad, try this:

require('total.js').cluster.https(5, 'debug', options);
neophylon commented 5 years ago

when I use

require('total.js').cluster.https(5, 'debug', options);

I still get the error "ERR_SSL_VERSION_OR_CIPHER_MISMATCH" on the Chrome browser

So, I try to modify my index.js and total.js/cluster.js.

index.js

options.https = {
    key: fs.readFileSync('/etc/letsencrypt/live/domain.com/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/domain.com/cert.pem')
}
==>
options.https = {
    key: '/etc/letsencrypt/live/domain.com/privkey.pem',
    cert: '/etc/letsencrypt/live/domain.com/cert.pem'
}

require('total.js').cluster.https(5, 'debug', options);

total.js/cluster.js

function on_init(msg){
......................
                        if (msg.https){
                msg.options.https.key = Fs.readFileSync(msg.options.https.key);
                msg.options.https.cert = Fs.readFileSync(msg.options.https.cert);
                    F.https(msg.mode, msg.options);
                }else{
                        F.http(msg.mode, msg.options);
                }
.....................

It works.

petersirka commented 5 years ago

Great, just create a pull request if you can to v3.2.0. Just let me know if you can't make pull request.

neophylon commented 5 years ago

Thank you, But it can't use with "require('total.js').https('debug',options);". So, I'm just temporary using it.

petersirka commented 5 years ago

Mhhh, I know where is the problem. Buffer (with of key + cert) is not sent to child process. I'll fix it today.

petersirka commented 5 years ago

I have fixed it. Sorry for delay. Try it $ npm install total.js@beta. Now you can use as you wrote:

options.https = {
    key: '/etc/letsencrypt/live/domain.com/privkey.pem',
    cert: '/etc/letsencrypt/live/domain.com/cert.pem'
};

// OR

options.https = {
    key: 'BASE64',
    cert: 'BASE64'
}

Thank you!

neophylon commented 5 years ago

I update total.js@beta. then try it I got the follow error

2019-01-18 13:39:10: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line Error: error:0906D06C:PEM routines:PEM_read_bio:no start line at Object.createSecureContext (_tls_common.js:88:17) at Server (_tls_wrap.js:819:25) at new Server (https.js:60:14) at Object.createServer (https.js:80:10) at listen (/opt/cluster_test/node_modules/total.js/index.js:6799:21) at /opt/cluster_test/node_modules/total.js/index.js:6826:6 at /opt/cluster_test/node_modules/total.js/index.js:3920:16 at Array.AP.async (/opt/cluster_test/node_modules/total.js/utils.js:5015:16) at /opt/cluster_test/node_modules/total.js/index.js:3915:16 at Array.AP.async (/opt/cluster_test/node_modules/total.js/utils.js:5015:16)

petersirka commented 5 years ago

Show me your code how you run the app.

neophylon commented 5 years ago

index.js // =================================================== // FOR DEVELOPMENT // Total.js - framework for Node.js platform // https://www.totaljs.com // ===================================================

const options = {}; options.ip = '0.0.0.0'; options.port = parseInt(process.argv[2]); options.https = { key:'/etc/letsencrypt/live/xxx.xxx.xxx/privkey.pem', cert:'/etc/letsencrypt/live/xxx.xxx.xxx/cert.pem' }

require('total.js').cluster.https(4, 'debug', options); //require('total.js').https('debug', options);

// Use a terminal for testing: // $ siege -b -r 10 http://127.0.0.1:8000/

total.js version : "total.js": "^3.2.0-6"

petersirka commented 5 years ago

I have tested it. It works correctly.

2019-01-18 13:39:10: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

This error means that you have invalid certificate or key.