基于ngrok实现natapp内网NAT穿透与反向代理的研究
因为之前为已经完成了,可能这里会省略一些步骤
使用到的工具:natapp.cn
前期准备
- 注册账号
- 实名认证
- 购买隧道
名称随便,协议www,端口要不被系统占用的(我的是4001)
在控制台获得一个16位的authtoken
- 下载客户端(windows x64 / mac x64) - 最新版
- 解压客户端
- 在客户端同级目录建立config.ini
写入以下内容(替换authtoken)
#将本文件放置于natapp同级目录 程序将读取 [default] 段
#在命令行参数模式如 natapp -authtoken=xxx 等相同参数将会覆盖掉此配置
#命令行参数 -config= 可以指定任意config.ini文件
[default]
authtoken=************* #对应一条隧道的authtoken
clienttoken= #对应客户端的clienttoken,将会忽略authtoken,若无请留空,
log=none #log 日志文件,可指定本地文件, none=不做记录,stdout=直接屏幕输出 ,默认为none
loglevel=ERROR #日志等级 DEBUG, INFO, WARNING, ERROR 默认为 DEBUG
http_proxy= #代理设置 如 http://10.123.10.10:3128 非代理上网用户请务必留空
- osx用户需要给权限
chmod +x natapp
- 运行 natapp,控制台返回
Powered By NATAPP Please visit https://natapp.cn (Ctrl+C to Quit)
Tunnel Status Online
Version 2.3.8
Forwarding http://*****.natappfree.cc -> 127.0.0.1:4001
Web Interface http://127.0.0.1:4040
Total Connections 0
得到类似上面的证明运行成功。
试试访问http://*****.natappfree.cc
配置失败应该返回的是:
Tunnel ancasc.natappfree.cc not found
配置Apache
开启多域名支持
OSX系统中XMAPP默认的配置文件是/Applications/XAMPP/xamppfiles/etc/httpd.conf
,可以找到Include etc/extra/httpd-vhosts.conf
这语句
则打开/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
文件
修改
VirtualHost文件
- 以下是路径的例子
<VirtualHost *:4001>
DocumentRoot "/private/var/www/xxx"
ServerName http://natappfree.cc:4001
ServerAlias http://*.natappfree.cc:4001
</VirtualHost>
- 以下是端口转发的例子
#natapp.cn
#NameVirtualHost *:4001
Listen 4001
<VirtualHost *:4001>
ProxyPreserveHost On
ServerName http://natappfree.cc:4001
ServerAlias http://*.natappfree.cc:4001
ProxyPass / http://localhost:9501/
ProxyPassReverse / http://localhost:9501/
</VirtualHost>
上面两个二选一
然后再次访问http://*****.natappfree.cc,页面就展示出来了。
[出现问题的调试方法]
首先要确定本地服务器是否能正常运行,可以通过设置Hosts的方法来确定问题。
127.0.0.1 http://*****.natappfree.cc
如果不能正常访问,请留言到哪一步,什么提示。
扫描二维码关注公众号,回复:
3455303 查看本文章