SSH反向通道

微信公众号调试,需要在微信管理后台配置一个微信能访问到的url,而且就算有一个公网的IP,本地调试也是不方便的。

那怎么本地调试呢?

  1. 本地电脑有公网IP。家里宽带,如果有独立IP的,可以在路由器里配置NAT地址转换。
  2. 使用ngrok这个东东。网上有资料(https://github.com/inconshreveable/ngrok)
  3. 使用ssh建立反向通道。

这里主要介绍使用第3种方法。ssh建立反向通道,通过ssh这条管道,穿透内网限制。

1.本地通过ssh连接远程服务器

ssh 命令格式:

ssh -R <remote port>:<local host>:<remote port> <SSH remote host>

示例:

  1. 远程外网可访问服务器:118.178.189.188:10001
  2. 本地服务器:localhost:8080
➜  ~ ssh -R 10001:localhost:8080 root@118.178.189.188

root@118.178.189.188's password:
Last login: Thu Apr 19 18:16:59 2018 from 42.48.85.122

Welcome to aliyun Elastic Compute Service!

[root@iZbp17jlki70utm0hl6ngoZ ~]#

输入密码,本地登入远程服务器(118.178.189.188)。

查看远程服务器的监听端口:

[root@iZbp17jlki70utm0hl6ngoZ ~]# netstat -anltp|grep 10001
tcp   0    0 0.0.0.0:10001  0.0.0.0:*   LISTEN  22482/sshd: root@pt

2.本地打开WEB服务

本地打开web工程的8080服务:

本地测试如(随意写了一个GET接口):

http://localhost:8080/

{
    "message": "Hello World!"
}

访问服务器端口查看是否连通到本地web服务:

http://118.178.189.188:10001/

{
    "message": "Hello World!"
}

3.通过nginx

配置nginx 下的 conf/vhost文件

增加一个配置

vim wx.jeiker.conf

内容如下:

server {                                                                                                                     
        listen 80;                                                                                                           
        server_name wx.jeiker.cn;                                                                                        
        error_log logs/wx.jeiker.error.log;                                                                               
        access_log logs/wx.jeiker.access.log;                                                                             

        location / {                                                                                                         
                proxy_pass http://127.0.0.1:10001;                                                                            
        }                                                                                                                    

        location ^~/WEB-INF {                                                                                                
                deny all;                                                                                                    
        }                                                                                                                    

        error_page 404 /html/common/error.html;                                                                              
        error_page 500 502 503 504 /html/common/error.html;                                                                  
}

重启nginx 使其配置生效:

./nginx -s reload

测试访问:

http://wx.jeiker.cn

{
    "message": "Hello World!"
}

猜你喜欢

转载自blog.csdn.net/jeikerxiao/article/details/80009269