写网页难免会遇到需要手机端测试或者远程测试的时候,这时候局域网就很不方便了。那么python+ngrok就可以完美解决这个问题。
首先,要确保本地安装了python且将其路径添加到了环境变量里,具体步骤可以自己百度哈,反正最后在终端里面运行python,如下:
➜ ~ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
出现版本号等信息 就表示python安装成功啦。
之后进入到要要运行的项目文件夹,输入
python -SimpleHTTPServer 80
就已经生成了一个简单的服务器。
以上步骤结束以后,在ngrok官网下载ngrok,然后把ngrok文件拖入到要运行的项目文件夹里,输入:
ngrok http 80
出现如下图所示:
ngrok by @inconshreveable
Session Status online
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://e75b4876.ngrok.io -> localhost:80
Forwarding https://e75b4876.ngrok.io -> localhost:80
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
这时,在手机端或者网页端打开http://e75b4876.ngrok.io就可以看到网页信息啦~
以上是ngrok一个简单的使用,还可以设置二级域名,这就需要用户注册了,感兴趣的小伙伴可以研究一下。
网友评论