简体   繁体   中英

Remote access to node.js

I'd like tu run my python scripts remotly using webbrowser.On my LAN server i have installed node.js. If I start these scripts by webbrowsrer on my server, all is OK. If I try to launch script on remote machine I can't see any response, but on server script starts (request without response?). Also proxy nginx settled on the server helped nothing. Summarizing, application is accessible only from the localhost, not from the remote machine.

At this point, my script application is accessible only from the localhost. I can't access it from the remote machine.

Node.js index.js file is:

    const express =  require('express');
    const { spawn } = require('child_process');
    const app = express();
    const port = 8811;

    app.get('/script', (req, res) => {
        let data1;
        const pythonOne = spawn('python3', ['script.py']);
        pythonOne.stdout.on('data', function(data){
            data1 = data.toString();
        })

        pythonOne.on('close', (code) => {
            console.log("code", code)
            res.send(data1);
        })  
    })

    app.listen(port, () => console.log('node python script app listening        on port ' + port));

My server is 192.168.1.161 Using http://192.168.1.161:8811/script on server, script.py starts OK. Using http://192.168.1.161:8811/script on remote machine script.py starts, but only on the server.

Additionally installed nginx with script.conf file:

    upstream backend {
    server localhost:8811;
    keepalive 32;
    }
    server {
    listen 8500;
    server_name script.example.com;
    location / {
        client_max_body_size 50M;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_pass http://backend;
    }       
    }

Now, Using http://192.168.1.161:8500/script on server script.py starts OK. Using http://192.168.1.161:8500/script on remote machine script.py starts, but only on the server.

Any answer will be appreciated.

绑定节点全部在 0.0.0.0

app.listen(port,'0.0.0.0' () => console.log('node python script app listening        on port ' + port));

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