目标:想要使用ngrok共享网站预览,这会创建一个隧道,从中可以看到我的localhost,其中包含类似 mywebsite.ngrok.io
的URL
问题:我使用WAMP,我的localhost文件夹看起来像这样:
localhostdirectory
|-- website1
|-- website2
|-- etc
要访问我在浏览器中输入 localhost/website1/
的网站,我想只隧道该URL,可能的解决方案是:
- 设置虚拟主机,I would go through the hassle of manually setting up a virtual host,然后我得到类似于website1.dev的东西,然后我将它作为HTTP请求中的主机头传递给ngrok,like that:
ngrok http -host-header=website1.dev 80
我没有't understand what the host header is though, and why can' t我传递了一个像 localhost/website1/
这样的相对网址,还有什么是重写选项?
- 将我的localhost的文件夹目录更改为网站的文件夹,我宁愿不这样做 .
有没有更好的方法以更简单的方式实现我的目标,也许通过WAMP别名?
3 回答
如果你使用Apache Vhost,你只需执行exec命令
ngrok http -host-header=rewrite YOUR-LOCAL-DOMAIN:PORT
别忘了编辑主机文件以解析@IP < - > YOUR-LOCAL-DOMAIN
将ngrok地址设置为指向端口80上的localhost后,您可以按名称访问您的网站 . 例如:
访问网站1:
我尝试了以下方式 .
当我运行
$ ./ngrok http 80
ngrok时,请听localhost:80
显示仪表板,因为apache服务器正在port 80
上运行 . 然后我尝试在另一个端口运行子文件夹 . 假设您在xyz
中有项目并希望ngrok指出它 . 然后做以下这里
8080
是任何未使用的端口 .localhost:8080
直接指向xyz
然后打开其他终端$ ./ngrok http 8080
通过这样做,ngrok将监听
8080
端口,你的xyz
正在运行 .希望这可以帮助!!