我发现了一个技巧,可以通过ssh将http隧道传输到我的本地计算机。
https://www.maketecheasier.com/reverse-ssh-tunnel-allow-external-connections/
我使用在本地计算机上运行Apache的web服务器,但希望从外部访问它,而不使用端口转发,而是使用VPS。原因是我使用移动设备(即笔记本电脑,但也可以是手机)作为web服务器。
假设本地设备具有端口8080作为http端口,并且VPS使用另一个端口(例如,标准80)。这个命令在我的本地计算机(macOS,Linux,甚至是使用Termux的安卓设备)上运行:
ssh -R 80:127.0.0.1:8080 root@VPS
当我通过http://VPS访问VPS时,我访问本地计算机的web界面。很好。这是可行的。
但是我想通过https访问它
ssh -R 443:127.0.0.1:8443 root@VPS
并安装Letsencrypt证书。我可以在VPS上这样做吗?还是应该在本地设备上这样做,并启用ssl.conf并使用8443作为安全端口?然后我想通过https://VPS上的VPS访问我的设备。
这有可能吗?
发布于 2021-07-10 23:11:03
我找到了答案。
我发现了这种方法:
Apache ssl.conf:
<VirtualHost *:443>
SSLEngine on
DocumentRoot /var/www/html/test/
ServerName my.example.com
LogLevel Debug
Include whitelist.conf
ErrorLog ${APACHE_LOG_DIR}/ssl-error.log
CustomLog ${APACHE_LOG_DIR}/ssl-access.log combined
SSLCertificateFile /root/.acme.sh/my.example.com/fullchain.cer
SSLCertificateKeyFile /root/.acme.sh/my.example.com/my.example.com.key
# SSLCertificateChainFile /root/.acme.sh/my.example.com/fullchain.cer
SSLProxyEngine On
ProxyRequests Off
# NON SSL access to be redirected to https://my.example.com:443
ProxyPass / http://my.anotherdomain.com:81/
ProxyPassReverse / http://my.anotherdomain.com:81/
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]
</VirtualHost>这会将我的设备的非SSL端口8080重定向到VPS (my.example.com:81)
ssh -p 22 -R 81:192.168.0.7:8080 root@myVPS -N或者在设备上,我可以在Termux中运行:
ssh -p 22 -R 81:127.0.0.1:8080 root@myVPS -N这使得我的设备SSL可以通过VPS主机使用my.example.com的证书进行访问。
https://stackoverflow.com/questions/68273236
复制相似问题