从外部访问本地主机 [英] Accessing localhost from outside

查看:104
本文介绍了从外部访问本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找在Android设备上运行node.js服务器的方法.我找到了一些描述它的好文章:

I have looked for some way to run node.js server on my android device. I found some good article describing it : https://medium.freecodecamp.com/building-a-node-js-application-on-android-part-1-termux-vim-and-node-js-dfa90c28958f#.xrh3v0du1. I have followed the tutorial and installed linux vm on my device and installed node.js. I have successed to run my node.js script and access it from android browser. But I can't find any way to open this page outside my android device by ip address.

推荐答案

如果您的TelCo允许,则可以按照以下步骤访问运行Node的本地主机android. 注意:仅当您使用手机数据计划(2-3-4-5 ... G数据)连接了移动设备时,此选项才有效;而当移动设备使用电话数据计划连接时,则无效使用Wi-Fi连接.需要明确的是:如果此移动设备不使用wi-fi数据,则您的应用程序只能通过以下方法在移动设备上提供内容.

You can access your localhost android running your Node, if your TelCo allow, following the below steps. Note: this is only valid when your mobile is connected using your phone data-plan (2-3-4-5... G data), and not when it's using a wi-fi connection. To be clear: your app, on your mobile, only serves content, by the below method, if this mobile is not using wi-fi data.

1-在动态dns提供商网站上设置一个帐户(始终支付良好的计划).在那里,您将配置一个URL,例如 http://muhlinin.mydyndns.com ,该URL指向动态IP.数字;

1 - setup an account in a dynamic dns provider website (good plans are always paid). There you will configure an URL like http://muhlinin.mydyndns.com which will be pointing to a dynamic IP number;

2-将相应的动态dns应用程序安装到您的手机中,该应用程序会将您当前的IP地址转发到您的动态dns帐户,以确保对 http://muhlinin.mydyndns.com 总是会找到您的移动设备来响应该请求,而不管您的移动设备在请求时拥有的IP是什么;

2 - install the respective dynamic dns app into your mobile, this app will forward your current IP number to your dynamic dns account, something that assures every request to http://muhlinin.mydyndns.com always will find your mobile to respond to that request, whatever IP your mobile has at the request time;

3-在运行(例如)Termux和Node的android上,使您的 .js服务器脚本侦听非默认端口(因为默认值80,可能会被电信公司关闭) ),例如8000,在您按照上面显示的项目1和2获得的动态网址上.像这样: http://muhlinin.mydyndns.com:8000

3 - on your android, running (for example) Termux and Node, make your .js server script listen to a not default port (cause the default, 80, may be closed by your TelCo), for example, 8000, on the dynamic url you got following itens 1 and 2 showed above. Something like this: http://muhlinin.mydyndns.com:8000

当然,如果您的手机关闭了,或者相应的dyn dns应用已关闭或未启动,或者您的Node服务器已关闭或未启动,则每次

Of course, if your mobile turns off, or the respective dyn dns app is closed or not started, or your Node server is closed or not started, every call to http://muhlinin.mydyndns.com:8000 will result in error. So, in order to have everything working, you have to have the previous 3 steps done correctly and all opened and started on your mobile server:

1-dyn dns应用程序;

1 - dyn dns app;

2-Node.js运行时;

2 - Node.js runtime;

3-您的serverscript.js(您将从在Termux上执行一个简单的"node serverscript.js"开始.

3 - your serverscript.js (which you will start by doing a simple 'node serverscript.js' on Termux.

这篇关于从外部访问本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆