{"_path":"/docs/3rd/ssh-tunnel","_draft":false,"_partial":false,"_empty":false,"title":"通过互联网访问本地服务","description":"使用 NGINX 配合 SSH 通道，可以把来自互联网的访问转发到在本地电脑上运行的服务来处理。","excerpt":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"通过互联网访问本地服务"},"children":[{"type":"text","value":"通过互联网访问本地服务"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"使用 NGINX 配合 SSH 通道，可以把来自互联网的访问转发到在本地电脑上运行的服务来处理。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在宁皓独立开发者训练营中调试微信支付与支付宝支付时，服务端应用需要处理这些支付服务发送过来的支付结果。为了能让在本地电脑上运行的服务端应用收到这些支付结果，就必须得保证能够直接通过互联网访问在本地电脑上运行的应用，可以使用 NGINX 与 SSH 通道的方式实现这个需求。"}]},{"type":"element","tag":"h2","props":{"id":"流程"},"children":[{"type":"text","value":"流程"}]},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"准备一台能通过互联网访问到的云服务器"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"配置域名 DNS 记录，指向云服务器的 IP 地址"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"在云服务器上安装配置 NGINX 反向代理服务器"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"在本地电脑，使用 SSH 在云服务器与本地电脑之间打个通道"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"先配置好一台能在互联网上被访问到的反向代理服务器（Web 服务器），服务器会将请求转发至本地服务器的某个特定端口，然后用 SSH 将这个服务器上的特定端口（比如 7689）与本地电脑上的某个特定端口（比如 3000）连通，这个本地电脑上的特定端口就是运行本地服务端应用时使用的端口，这样当有人在互联网访问这个反向代理服务器时，实际提供服务的是在我们本地电脑上运行的服务端应用。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/3rd/ssh-tunnel/image.png"},"children":[]}]},{"type":"element","tag":"h2","props":{"id":"添加域名-dns-记录"},"children":[{"type":"text","value":"添加域名 DNS 记录"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在域名服务商提供的域名管理界面，添加一条 A 类型的 DNS 记录，记录值是我们的云服务器的 IP 地址，主机名可以随意设置。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"比如我为 "},{"type":"element","tag":"a","props":{"href":"http://ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"ninghao.net"}]},{"type":"text","value":" 这个域名添加了一条 DNS 记录，让 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":" 指向我的一台云服务器，准备好 NGINX 服务器与 SSH 通道以后，就可以在互联网通过这个域名直接访问在我本地电脑上运行的应用了。"}]},{"type":"element","tag":"h2","props":{"id":"创建反向代理服务器"},"children":[{"type":"text","value":"创建反向代理服务器"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"使用 SSH 远程登录云服务器以后，需要配置一个 NGINX 的反向代理服务器。"}]},{"type":"element","tag":"code","props":{"code":"vi /etc/nginx/conf.d/sandbox.ninghao.net.conf\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"vi /etc/nginx/conf.d/sandbox.ninghao.net.conf\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"内容如下："}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"/etc/nginx/conf.d/sandbox.ninghao.net.conf"}]}]},{"type":"element","tag":"code","props":{"code":"server {\n  listen                      80;\n  server_name                 sandbox.ninghao.net;\n  client_max_body_size        200m;\n\n  location / {\n    proxy_set_header          X-Real-IP $remote_addr;\n    proxy_set_header          X-Real-Port $remote_port;\n    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header          Host $http_host;\n    proxy_set_header          X-Forwarded-Proto $scheme;\n    proxy_http_version 1.1;\n    proxy_set_header          Upgrade $http_upgrade;\n    proxy_set_header          Connection \"upgrade\";\n    proxy_redirect            off;\n    expires                   off;\n    sendfile                  off;\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"server {\n  listen                      80;\n  server_name                 sandbox.ninghao.net;\n  client_max_body_size        200m;\n\n  location / {\n    proxy_set_header          X-Real-IP $remote_addr;\n    proxy_set_header          X-Real-Port $remote_port;\n    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header          Host $http_host;\n    proxy_set_header          X-Forwarded-Proto $scheme;\n    proxy_http_version 1.1;\n    proxy_set_header          Upgrade $http_upgrade;\n    proxy_set_header          Connection \"upgrade\";\n    proxy_redirect            off;\n    expires                   off;\n    sendfile                  off;\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"上面这个 NGINX 配置，创建了一台反向代理服务器，监听的端口是 80，绑定的域名是 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":"，在用一个 location 区块，配置一下代理服务相关的东西，注意这里的 proxy_pass 指令的值被设置成了 "},{"type":"element","tag":"a","props":{"href":"http://127.0.0.1:7689%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%BD%93%E6%9C%89%E4%BA%BA%E8%AE%BF%E9%97%AE/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://127.0.0.1:7689，意思是将访问转发到本地"}]},{"type":"text","value":"服务器的 7689 这个端口。"},{"type":"element","tag":"a","props":{"href":"http://127.0.0.1:7689%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%BD%93%E6%9C%89%E4%BA%BA%E8%AE%BF%E9%97%AE/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"也就是当有人访问"}]},{"type":"text","value":" "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://sandbox.ninghao.net"}]},{"type":"text","value":" 的时候，这个反向代理服务器会将请求转给本地服务器的 7689 这个端口。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果你希望通过 HTTPS 访问这个服务器，可以使用 certbot，为 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":" 这个域名申请一个 SSL 证书。完成以后，这个 NGINX 服务器的配置文件看起来会像下面这样："}]},{"type":"element","tag":"code","props":{"code":"server {\n  listen                      443 ssl http2;\n  server_name                 sandbox.ninghao.net;\n  ...\n\n  ssl_certificate /etc/letsencrypt/live/sandbox.ninghao.net/fullchain.pem; # managed by Certbot\n  ssl_certificate_key /etc/letsencrypt/live/sandbox.ninghao.net/privkey.pem; # managed by Certbot\n  include /etc/letsencrypt/options-ssl-nginx.conf;\n  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;\n\n  location / {\n    ...\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"server {\n  listen                      443 ssl http2;\n  server_name                 sandbox.ninghao.net;\n  ...\n\n  ssl_certificate /etc/letsencrypt/live/sandbox.ninghao.net/fullchain.pem; # managed by Certbot\n  ssl_certificate_key /etc/letsencrypt/live/sandbox.ninghao.net/privkey.pem; # managed by Certbot\n  include /etc/letsencrypt/options-ssl-nginx.conf;\n  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;\n\n  location / {\n    ...\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"}]}]}]},{"type":"element","tag":"h2","props":{"id":"ssh-通道"},"children":[{"type":"text","value":"SSH 通道"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"回到本地电脑上，确定在本地电脑上的服务端应用已经运行了，这个应用通过 3000 这个端口提供服务。现在我们要使用 SSH，在本地电脑与云服务器之间打个通道。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"ssh -vnNT -R 7689:localhost:3000 root@42.120.40.68\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"ssh -vnNT -R 7689:localhost:3000 root@42.120.40.68\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开本地电脑的终端，执行 ssh 命令，要加上一些参数，比如 vnNT 这四个参数，还需要一个 R 参数，具体这些参数表示的意思可以执行 man ssh 命令，查看 ssh 命令的使用说明。7689 指的是远程云服务器上的一个端口，还记得上面我们配置的那台 NGINX 反向代理服务器吗？它会将访问转发到 7689 这个端口。localhost:3000 是我在本地电脑上运行的服务端应用的地址。root 是远程登录服务器时使用的用户名，42.120.40.68 是我的云服务器的 IP 地址。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"一切正常会出现下面这样的文字："}]},{"type":"element","tag":"code","props":{"code":"remote forward success for: listen 7689, connect localhost:3000\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"remote forward success for: listen 7689, connect localhost:3000\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"现在如果有人通过互联网访问 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":"，服务器会将请求转发到 7689 这个端口，又因为我们使用 SSH 在本地电脑与云服务器之间打了一个通道，这个通道的服务器这一边，设置使用的端口号是 7689，本地电脑这边的地址是 localhost:3000，这样访问 sandbox.ninghao.net，实际提供服务的就是在我们本地电脑上运行的应用。"}]}]},"body":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"通过互联网访问本地服务"},"children":[{"type":"text","value":"通过互联网访问本地服务"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"使用 NGINX 配合 SSH 通道，可以把来自互联网的访问转发到在本地电脑上运行的服务来处理。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在宁皓独立开发者训练营中调试微信支付与支付宝支付时，服务端应用需要处理这些支付服务发送过来的支付结果。为了能让在本地电脑上运行的服务端应用收到这些支付结果，就必须得保证能够直接通过互联网访问在本地电脑上运行的应用，可以使用 NGINX 与 SSH 通道的方式实现这个需求。"}]},{"type":"element","tag":"h2","props":{"id":"流程"},"children":[{"type":"text","value":"流程"}]},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"准备一台能通过互联网访问到的云服务器"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"配置域名 DNS 记录，指向云服务器的 IP 地址"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"在云服务器上安装配置 NGINX 反向代理服务器"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"在本地电脑，使用 SSH 在云服务器与本地电脑之间打个通道"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"先配置好一台能在互联网上被访问到的反向代理服务器（Web 服务器），服务器会将请求转发至本地服务器的某个特定端口，然后用 SSH 将这个服务器上的特定端口（比如 7689）与本地电脑上的某个特定端口（比如 3000）连通，这个本地电脑上的特定端口就是运行本地服务端应用时使用的端口，这样当有人在互联网访问这个反向代理服务器时，实际提供服务的是在我们本地电脑上运行的服务端应用。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/3rd/ssh-tunnel/image.png"},"children":[]}]},{"type":"element","tag":"h2","props":{"id":"添加域名-dns-记录"},"children":[{"type":"text","value":"添加域名 DNS 记录"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在域名服务商提供的域名管理界面，添加一条 A 类型的 DNS 记录，记录值是我们的云服务器的 IP 地址，主机名可以随意设置。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"比如我为 "},{"type":"element","tag":"a","props":{"href":"http://ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"ninghao.net"}]},{"type":"text","value":" 这个域名添加了一条 DNS 记录，让 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":" 指向我的一台云服务器，准备好 NGINX 服务器与 SSH 通道以后，就可以在互联网通过这个域名直接访问在我本地电脑上运行的应用了。"}]},{"type":"element","tag":"h2","props":{"id":"创建反向代理服务器"},"children":[{"type":"text","value":"创建反向代理服务器"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"使用 SSH 远程登录云服务器以后，需要配置一个 NGINX 的反向代理服务器。"}]},{"type":"element","tag":"code","props":{"code":"vi /etc/nginx/conf.d/sandbox.ninghao.net.conf\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"vi /etc/nginx/conf.d/sandbox.ninghao.net.conf\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"内容如下："}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"/etc/nginx/conf.d/sandbox.ninghao.net.conf"}]}]},{"type":"element","tag":"code","props":{"code":"server {\n  listen                      80;\n  server_name                 sandbox.ninghao.net;\n  client_max_body_size        200m;\n\n  location / {\n    proxy_set_header          X-Real-IP $remote_addr;\n    proxy_set_header          X-Real-Port $remote_port;\n    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header          Host $http_host;\n    proxy_set_header          X-Forwarded-Proto $scheme;\n    proxy_http_version 1.1;\n    proxy_set_header          Upgrade $http_upgrade;\n    proxy_set_header          Connection \"upgrade\";\n    proxy_redirect            off;\n    expires                   off;\n    sendfile                  off;\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"server {\n  listen                      80;\n  server_name                 sandbox.ninghao.net;\n  client_max_body_size        200m;\n\n  location / {\n    proxy_set_header          X-Real-IP $remote_addr;\n    proxy_set_header          X-Real-Port $remote_port;\n    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header          Host $http_host;\n    proxy_set_header          X-Forwarded-Proto $scheme;\n    proxy_http_version 1.1;\n    proxy_set_header          Upgrade $http_upgrade;\n    proxy_set_header          Connection \"upgrade\";\n    proxy_redirect            off;\n    expires                   off;\n    sendfile                  off;\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"上面这个 NGINX 配置，创建了一台反向代理服务器，监听的端口是 80，绑定的域名是 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":"，在用一个 location 区块，配置一下代理服务相关的东西，注意这里的 proxy_pass 指令的值被设置成了 "},{"type":"element","tag":"a","props":{"href":"http://127.0.0.1:7689%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%BD%93%E6%9C%89%E4%BA%BA%E8%AE%BF%E9%97%AE/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://127.0.0.1:7689，意思是将访问转发到本地"}]},{"type":"text","value":"服务器的 7689 这个端口。"},{"type":"element","tag":"a","props":{"href":"http://127.0.0.1:7689%EF%BC%8C%E4%B9%9F%E5%B0%B1%E6%98%AF%E5%BD%93%E6%9C%89%E4%BA%BA%E8%AE%BF%E9%97%AE/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"也就是当有人访问"}]},{"type":"text","value":" "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://sandbox.ninghao.net"}]},{"type":"text","value":" 的时候，这个反向代理服务器会将请求转给本地服务器的 7689 这个端口。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果你希望通过 HTTPS 访问这个服务器，可以使用 certbot，为 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":" 这个域名申请一个 SSL 证书。完成以后，这个 NGINX 服务器的配置文件看起来会像下面这样："}]},{"type":"element","tag":"code","props":{"code":"server {\n  listen                      443 ssl http2;\n  server_name                 sandbox.ninghao.net;\n  ...\n\n  ssl_certificate /etc/letsencrypt/live/sandbox.ninghao.net/fullchain.pem; # managed by Certbot\n  ssl_certificate_key /etc/letsencrypt/live/sandbox.ninghao.net/privkey.pem; # managed by Certbot\n  include /etc/letsencrypt/options-ssl-nginx.conf;\n  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;\n\n  location / {\n    ...\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"server {\n  listen                      443 ssl http2;\n  server_name                 sandbox.ninghao.net;\n  ...\n\n  ssl_certificate /etc/letsencrypt/live/sandbox.ninghao.net/fullchain.pem; # managed by Certbot\n  ssl_certificate_key /etc/letsencrypt/live/sandbox.ninghao.net/privkey.pem; # managed by Certbot\n  include /etc/letsencrypt/options-ssl-nginx.conf;\n  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;\n\n  location / {\n    ...\n    proxy_pass                http://127.0.0.1:7689;\n  }\n}\n"}]}]}]},{"type":"element","tag":"h2","props":{"id":"ssh-通道"},"children":[{"type":"text","value":"SSH 通道"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"回到本地电脑上，确定在本地电脑上的服务端应用已经运行了，这个应用通过 3000 这个端口提供服务。现在我们要使用 SSH，在本地电脑与云服务器之间打个通道。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"ssh -vnNT -R 7689:localhost:3000 root@42.120.40.68\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"ssh -vnNT -R 7689:localhost:3000 root@42.120.40.68\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开本地电脑的终端，执行 ssh 命令，要加上一些参数，比如 vnNT 这四个参数，还需要一个 R 参数，具体这些参数表示的意思可以执行 man ssh 命令，查看 ssh 命令的使用说明。7689 指的是远程云服务器上的一个端口，还记得上面我们配置的那台 NGINX 反向代理服务器吗？它会将访问转发到 7689 这个端口。localhost:3000 是我在本地电脑上运行的服务端应用的地址。root 是远程登录服务器时使用的用户名，42.120.40.68 是我的云服务器的 IP 地址。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"一切正常会出现下面这样的文字："}]},{"type":"element","tag":"code","props":{"code":"remote forward success for: listen 7689, connect localhost:3000\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"remote forward success for: listen 7689, connect localhost:3000\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"现在如果有人通过互联网访问 "},{"type":"element","tag":"a","props":{"href":"http://sandbox.ninghao.net/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"sandbox.ninghao.net"}]},{"type":"text","value":"，服务器会将请求转发到 7689 这个端口，又因为我们使用 SSH 在本地电脑与云服务器之间打了一个通道，这个通道的服务器这一边，设置使用的端口号是 7689，本地电脑这边的地址是 localhost:3000，这样访问 sandbox.ninghao.net，实际提供服务的就是在我们本地电脑上运行的应用。"}]}],"toc":{"title":"","searchDepth":2,"depth":2,"links":[{"id":"流程","depth":2,"text":"流程"},{"id":"添加域名-dns-记录","depth":2,"text":"添加域名 DNS 记录"},{"id":"创建反向代理服务器","depth":2,"text":"创建反向代理服务器"},{"id":"ssh-通道","depth":2,"text":"SSH 通道"}]}},"_type":"markdown","_id":"content:docs:3.3rd:6.ssh-tunnel.md","_source":"content","_file":"docs/3.3rd/6.ssh-tunnel.md","_extension":"md"}