简体   繁体   English

远程访问 node.js

[英]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.我想使用 webbrowser 远程运行我的 python 脚本。在我的 LAN 服务器上,我安装了 node.js。 If I start these scripts by webbrowsrer on my server, all is OK.如果我通过服务器上的 webbrowsrer 启动这些脚本,一切正常。 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.在服务器上安装的代理 nginx 也没有任何帮助。 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: Node.js index.js 文件是:

    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.我的服务器是 192.168.1.161 在服务器上使用http://192.168.1.161:8811/script,script.py启动正常。 Using http://192.168.1.161:8811/script on remote machine script.py starts, but only on the server.在远程机器上使用http://192.168.1.161:8811/script script.py 启动,但仅在服务器上。

Additionally installed nginx with script.conf file:另外安装了带有 script.conf 文件的 nginx:

    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.现在,在服务器 script.py 上使用http://192.168.1.161:8500/script开始正常。 Using http://192.168.1.161:8500/script on remote machine script.py starts, but only on the server.在远程机器上使用http://192.168.1.161:8500/script script.py 启动,但仅在服务器上。

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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