news 2026/4/16 11:16:09

【怎么在手机上访问部署在电脑上的网页,不在一个局域网】

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
【怎么在手机上访问部署在电脑上的网页,不在一个局域网】

其实可以使用cloudefare提供的那个,支持使用自己的域名

百度回答

方法一:使用内网穿透工具(推荐)

通过工具如贝锐蒲公英或Ngrok,将本地服务映射到公网,手机直接访问生成的公网地址即可。无需公网IP,支持跨运营商访问。

方法二:远程桌面工具

在电脑端设置远程桌面(如Windows远程桌面),手机端安装对应客户端,通过输入电脑的公网IP和凭证连接。需注意网络稳定性和流量消耗。

方法三:VPN组网

在电脑端搭建VPN服务器(如OpenVPN),手机连接后形成虚拟局域网,即可访问电脑本地服务。适合技术基础较强的用户。

注意‌:公网访问需确保电脑防火墙放行对应端口,并注意网络安全风险。

ngrok config add-authtoken $YOUR_AUTHTOKEN

ngrok http 5000


python 代码

# app.pyfromflaskimportFlask,render_template_string,Responsefromdatetimeimportdatetimeimporttimeimportthreading app=Flask(__name__)# 首页HTML=""" <!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>实时时间 + 计算器</title> <style> body{font-family:Arial,Helvetica,sans-serif;text-align:center;margin-top:40px;background:#f7f7f7;} #clock{font-size:48px;margin-bottom:30px;} .calc{border-collapse:collapse;margin:0 auto 20px;} .calc td{padding:0;} .calc button{width:70px;height:60px;font-size:22px;border:1px solid #bbb;background:#fff;cursor:pointer;} .calc button:active{background:#ddd;} #display{width:100%;height:60px;font-size:28px;text-align:right;padding:0 10px;box-sizing:border-box;} </style> </head> <body> <div id="clock">--:--:--</div> <table class="calc"> <tr> <td colspan="4"><input id="display" disabled></td> </tr> <tr> <td><button onclick="press('7')">7</button></td> <td><button onclick="press('8')">8</button></td> <td><button onclick="press('9')">9</button></td> <td><button onclick="press('/')">÷</button></td> </tr> <tr> <td><button onclick="press('4')">4</button></td> <td><button onclick="press('5')">5</button></td> <td><button onclick="press('6')">6</button></td> <td><button onclick="press('*')">×</button></td> </tr> <tr> <td><button onclick="press('1')">1</button></td> <td><button onclick="press('2')">2</button></td> <td><button onclick="press('3')">3</button></td> <td><button onclick="press('-')">−</button></td> </tr> <tr> <td><button onclick="press('0')">0</button></td> <td><button onclick="press('.')">.</button></td> <td><button onclick="press('=')">=</button></td> <td><button onclick="press('+')">+</button></td> </tr> <tr> <td colspan="2"><button onclick="clr()">C</button></td> <td colspan="2"><button onclick="del()">⌫</button></td> </tr> </table> <script> // 实时时间 SSE const clock = document.getElementById('clock'); const evtSource = new EventSource('/time'); evtSource.onmessage = e => clock.textContent = e.data; // 计算器 let expr = ''; function press(k){ if(k === '='){ try{ expr = String(eval(expr)); } catch(e){ expr = 'Error'; } }else{ expr += k; } document.getElementById('display').value = expr; } function clr(){ expr = ''; document.getElementById('display').value = ''; } function del(){ expr = expr.slice(0,-1); document.getElementById('display').value = expr; } </script> </body> </html> """@app.route('/')defindex():returnrender_template_string(HTML)# Server-Sent Events:每秒推送一次当前时间deftime_gen():whileTrue:yieldf"data:{datetime.now().strftime('%H:%M:%S')}\n\n"time.sleep(1)@app.route('/time')deftime_stream():returnResponse(time_gen(),mimetype="text/event-stream")if__name__=='__main__':# threaded=True 保证 SSE 不阻塞app.run(host='0.0.0.0',port=5000,threaded=True)

还有
Cloudflare Tunnel(原 Argo Tunnel)——
要“下载一个官方软件”cloudflared,然后在本地跑一条加密隧道到 Cloudflare 边缘节点,
不需要公网 IP、不需要 ngrok、不需要开端口
再把自定义域名解析到这条隧道,任何设备都能访问。下面是最新的完整步骤(2024-2025 版)。


一、准备工作

  1. 一个已托管到 Cloudflare 的域名(NS 指向 CF 即可,免费版也行)。
  2. 本地电脑(Windows / macOS / Linux / 树莓派均可)能跑你的 Web 服务。
  3. 有管理员权限安装cloudflared

二、安装 cloudflared

Windows(PowerShell 管理员)

# 1. 下载Invoke-WebRequest-Uri"https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe"-OutFile"C:\Windows\System32\cloudflared.exe"# 2. 验证cloudflared--version

macOS

brewinstallcloudflared

Linux(Debian/Ubuntu)

wget-q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.debsudodpkg -i cloudflared-linux-amd64.deb

三、一键登录 & 创建隧道

  1. 登录(浏览器会弹出授权)

    cloudflared tunnel login

    成功后会在~/.cloudflared/生成cert.pem

  2. 创建隧道(名字随便取,这里叫my-demo

    cloudflared tunnel create my-demo

    控制台会返回一行Tunnel IDxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    同时本地会生成xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json凭证文件,别丢


四、把域名绑到隧道(CNAME 方式)

假设你想用demo.example.com访问本地 5000 端口:

  1. 添加 DNS 记录
    cloudflared tunnel route dns my-demo demo
    这条命令会自动在 Cloudflare 控制台插入一条 CNAME:
    demo.example.com<Tunnel-ID>.cfargotunnel.com
    代理状态默认 ☁️橙色(开启),无需手动再点。

五、写配置文件(一次写好,以后直接cloudflared tunnel run

新建文件~/.cloudflared/config.yml(Windows 路径相同):

tunnel:<Tunnel-ID># 上一步生成的 IDcredentials-file:/home/你的用户名/.cloudflared/<Tunnel-ID>.jsoningress:-hostname:demo.example.comservice:http://localhost:5000-service:http_status:404# 默认兜底

六、启动隧道

cloudflared tunnel run my-demo

看到Connected ...即表示本地 5000 端口已通过加密隧道到达 Cloudflare 边缘节点。


七、手机/外网测试

  1. 电脑保持cloudflared运行。
  2. 手机断开 Wi-Fi(用 4G/5G)打开浏览器输入
    https://demo.example.com
    首次访问会慢 1-2 秒,之后全球任何网络都能打开,地址栏直接有小锁(Cloudflare 边缘证书自动签发)。

八、常用补充

  • 换端口/换域名:改config.yml后重启隧道即可。
  • 后台运行:
    Linux 用 systemd:sudo cloudflared service install
    Windows 用 NSSM 或任务计划程序。
  • 同时暴露多个服务:在ingress里继续加- hostname: xxx即可。
  • 卸载:
    cloudflared tunnel delete my-demo
    再到 Cloudflare 控制台把对应 DNS 记录删掉即可。

cloudflaredcloudflared tunnel createcloudflared tunnel route dns→ 写config.ymlcloudflared tunnel run→ 手机用你自己的域名随时随地访问本地网页,无需公网 IP、无需 ngrok、免费 SSL+CDN

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 14:00:10

KataGo TensorRT引擎终极指南:轻松解决DLL加载失败问题

KataGo TensorRT引擎终极指南&#xff1a;轻松解决DLL加载失败问题 【免费下载链接】KataGo GTP engine and self-play learning in Go 项目地址: https://gitcode.com/gh_mirrors/ka/KataGo KataGo是一个强大的围棋AI项目&#xff0c;结合了GTP引擎和自学习能力。该项目…

作者头像 李华
网站建设 2026/4/16 12:39:46

大模型填充原因解释

1、大模型qkv 并计算注意力分数阶段 为啥需要填充 这个问题问得非常“底层”&#xff0c;我直接从本质讲&#xff0c;不绕&#xff0c;也不省略任何关键细节。一句话先给结论&#xff08;本质&#xff09; 在 QKV 并计算注意力分数阶段需要“填充&#xff08;padding&#xff0…

作者头像 李华
网站建设 2026/4/16 15:02:55

PIVlab粒子图像测速终极指南:从零开始掌握流体可视化

PIVlab粒子图像测速终极指南&#xff1a;从零开始掌握流体可视化 【免费下载链接】PIVlab Particle Image Velocimetry for Matlab, official repository 项目地址: https://gitcode.com/gh_mirrors/pi/PIVlab 还在为复杂的流体力学实验感到困惑吗&#xff1f;PIVlab粒子…

作者头像 李华
网站建设 2026/4/16 16:45:12

终极IoTSharp部署指南:快速搭建企业级物联网平台

终极IoTSharp部署指南&#xff1a;快速搭建企业级物联网平台 【免费下载链接】IoTSharp IoTSharp is an open-source IoT platform for data collection, processing, visualization, and device management. 项目地址: https://gitcode.com/gh_mirrors/io/IoTSharp IoT…

作者头像 李华
网站建设 2026/4/16 14:04:51

WebUploader如何支持多平台的大文件断点续传?

作为一名自由职业者&#xff0c;我最近接了一个外包项目。客户是一家在行业内颇具影响力的企业&#xff0c;他们现有的 WEB 系统需要新增大文件上传功能&#xff0c;具体要求是能在页面上支持 10G 左右大文件的上传和续传。 客户对这个项目十分重视&#xff0c;毕竟这关系到他…

作者头像 李华
网站建设 2026/4/15 21:45:33

仓颉编程语言:现代开发者的终极选择

仓颉编程语言&#xff1a;现代开发者的终极选择 【免费下载链接】CangjieCommunity 为仓颉编程语言开发者打造活跃、开放、高质量的社区环境 项目地址: https://gitcode.com/Cangjie/CangjieCommunity 仓颉编程语言作为一款面向全场景的智能化应用编程语言&#xff0c;正…

作者头像 李华