本地电脑变成服务器,外网随时连接「免费内网穿透」
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">对于开发人员来说,如果每次都将项目部署到公网的服务器,才可以实现外网访问,这样太麻烦了。所以我每次都是做内网穿透来实现外网访问,以本地电脑做服务器,将内网端口映射到公网,生成公网地址来访问,比较简单。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">内网穿透工具,我采用的是cpolar内网穿透,支持http/https/tcp协议,不限制流量,也不需要公网IP,不用进入到路由器设置,可以永久免费使用。不过免费使用所生成的是随机临时的公网地址,每隔24小时就会变化,但是临时测试使用足够了。当然,你也可以升级套餐配置固定的公网地址,增大带宽,使用更多功能,cpolar支持21天退款保证。</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1. 安装cpolar内网穿透工具</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">cpolar内网穿透官网:<a style="color: red;">cpolar - 安全的内网穿透工具</a></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">需要先注册一个cpolar账号,后面会用到。</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1.1 Windows</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">windows系统可以在cpolar官网下载最新的安装包,然后解压默认安装即可。</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1.2 Linux</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">linux系统支持一键自动安装脚本</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1.2.1 安装</h1><span style="color: green;">国内使用</span><span style="color: green;">curl</span> -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash<span style="color: green;">国外使用</span><span style="color: green;">curl</span> -sL https://git.io/cpolar | sudo bash<h1 style="text-align: left; margin-bottom: 10px;">1.2.2 向系统添加服务</h1>sudo systemctl <span style="color: green;">enable</span> cpolar<h1 style="text-align: left; margin-bottom: 10px;">1.2.3 启动服务</h1><span style="color: green;">sudo</span> systemctl start cpolar<h1 style="text-align: left; margin-bottom: 10px;">1.2.4 查看服务状态</h1>sudo systemctl <span style="color: green;">status</span> cpolar<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">如正常显示active,则说明已经启动成功。</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1.3 macOS</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">在官网下载下载适用于macOS平台的zip压缩包,解压后得到cpolar,然后通过命令行带参数运行即可。</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1.3.1 通过Homebrew包管理器安装</h1><span style="color: green;">brew</span> tap probezy/core && brew install cpolar<h1 style="text-align: left; margin-bottom: 10px;">1.3.2 token认证</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">登录cpolar官网后台————验证,查看自己的认证token,之后将token贴在命令行里</span></p><span style="color: green;">cpolar</span> authtoken xxxxxxx<h1 style="text-align: left; margin-bottom: 10px;">1.3.2 安装服务</h1><span style="color: green;">sudo</span> cpolar service install<h1 style="text-align: left; margin-bottom: 10px;">1.3.2 启动服务</h1><span style="color: green;">sudo</span> cpolar service start<h1 style="text-align: left; margin-bottom: 10px;">2. 创建隧道映射内网端口</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">cpolar安装成功后,在浏览器上访问127.0.0.1:9200,使用cpolar账号登录web UI管理界面。</span></p>
<div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/682d939e2c5946cfa581dc5ec5d699e3~noop.image?_iz=58558&from=article.pc_detail&x-expires=1679809356&x-signature=37Iu5xRK2UfPskIgGygDE1GOv9M%3D" style="width: 100%; margin-bottom: 20px;"></div>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">登录成功后,进入主界面</span></p>
<div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/35f30cb8405446419f512eb515781e78~noop.image?_iz=58558&from=article.pc_detail&x-expires=1679809356&x-signature=RMgvnIGO7xMOz9cA0f2C6u0Qa%2BU%3D" style="width: 100%; margin-bottom: 20px;"></div>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">比如,我们需要将本地8080端口下的web站点发布到公网可访问,只需要点击左侧仪表盘的隧道管理————创建隧道,输入隧道信息,然后点击创建即可。</span></p><span style="color: green;">隧道名称:可自定义,注意不要重复</span><span style="color: green;">协议:选择http协议</span><span style="color: green;">本地地址:填写8080端口</span><span style="color: green;">域名类型:选择随机域名(可免费使用)</span><span style="color: green;">地区:选择China VIP</span>
<div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/4a052430b7884c33b4d62a2e0464bc7b~noop.image?_iz=58558&from=article.pc_detail&x-expires=1679809356&x-signature=0ggUQ3XnbQiY2fJ5X3ya%2BqyaiEM%3D" style="width: 100%; margin-bottom: 20px;"></div>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">隧道创建成功后,可以在隧道管理————隧道列表查看隧道状态,如为active激活。说明已经启动成功。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">cpolar会默认安装两个样例隧道,一个是Website隧道指向http 8080端口,一个是ssh隧道(Linux&macOS系统)/远程桌面隧道(win系统),指向tcp 22端口/tcp 3389端口。</span></p>
<div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/1ee94a6ef3864b0c80549c8bf8066519~noop.image?_iz=58558&from=article.pc_detail&x-expires=1679809356&x-signature=j3OuR6yd2u2sl%2FVukboyTUGzrHU%3D" style="width: 100%; margin-bottom: 20px;"></div>
<h1 style="text-align: left; margin-bottom: 10px;">3. 获取公网地址</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">点击左侧仪表盘的状态————在线隧道列表,找到我们刚刚创建的隧道,可以看到有生成相应的公网URL地址,有两行,其中一个是http隧道,一个是https隧道。</span></p>
<div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/8af1eb87e1644d89b13331d5d780408b~noop.image?_iz=58558&from=article.pc_detail&x-expires=1679809356&x-signature=mu2lwt7klxIwNKeqGr%2FCA3UPmko%3D" style="width: 100%; margin-bottom: 20px;"></div>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">将公网地址复制到浏览器访问即可,实现公网远程访问内网。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">显示如下图灰色的画面,这说明,cpolar已经配置正确,隧道创建成功。只是本地8080端口上,并未发现可用的web站点(因为还没有配置本地Web Server。所以才会显示灰色不可用的画面。如果你本地有正常配置页面,那么就会正常显示出来。)</span></p>
<div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/8c2306b842854778b0896b621a4247ef~noop.image?_iz=58558&from=article.pc_detail&x-expires=1679809356&x-signature=s%2B1bDj7PoIM%2F%2F7adBt%2F2yKhTO4M%3D" style="width: 100%; margin-bottom: 20px;"></div>
页:
[1]