受欢迎的博客标签

Intranet Penetration-nginx + ssh to access home computer local services

Published

1.Server (public ipAddress)

修改 nginx/conf/nginx.conf 配置文件
增加要映射的端口:

server {
    listen       80;
    server_name  localhost;

    location / {
      proxy_pass http://127.0.0.1:8999;  //开放一个本地端口,用来转发上面定义的 80 端口的内容
    }
}

 

2.client (home computer local )

在内网设备上建立 ssh 反向隧道/远程转发 请求转发,即把服务器请求转发到本地:

ssh -fCNR [B机器IP或省略]:[B机器端口]:[A机器的IP]:[A机器的sshd端口] [登录B机器的用户名@B机器的IP] -p [B机器的sshd端口]

 

内网机器的服务端口是8080,反向代理到外网机器的8999端口,在内网机器上操作:

ssh -fCNR 8999:localhost:8080 -o ServerAliveInterval=60 [email protected] -p 2
至此就成功了。
访问公网ip就会自动重定向到内网的服务了。

Useful links

SSH reverse proxy implements intranet penetration; SSH + nginx enables the public cloud server proxy to access the intranet server