浏览器无法通过安全SSH隧道连接到web2py

时间:2016-12-13 11:59:19

标签: ssh web2py

我跟着the instructions in the web2py manual on how to connect to a remote web2py via ssh tunnel。 SSH到我的服务器似乎工作正常:

[~/prg]$ ssh -L 8002:127.0.0.1:8002 username@linux-server.com
Linux schemelab2 4.6.5-x86_64-linode71 #2 SMP Fri Jul 29 16:16:25 EDT 2016 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.

just as others have failed,当我尝试访问http://localhost:8002https://localhost:8002时,我收到了许多拒绝连接的消息:

channel 3: open failed: connect failed: Connection refused
channel 4: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 4: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused

如果有帮助,here is my sshd_config

另请注意: telnet localhost 8002产生

schemelab@schemelab2:~$ telnet localhost 8002
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
schemelab@schemelab2:~$ 

1 个答案:

答案 0 :(得分:2)

可能是几个可能的原因之一。我假设您最感兴趣的是访问远程服务器上的web2py管理页面,因为web2py不允许通过不安全的通道进行远程管理访问...首先,您要确保服务器的IP表允许访问您尝试连接的端口上的服务,否则这些远程连接解决方​​案可能无法工作(可能除了Plan C)。有关详细信息,请参阅此处:https://help.ubuntu.com/community/IptablesHowTo

首先,让我向您展示我是如何通过我过去使用的数十台服务器通过SSH隧道连接到web2py的。我将在我的示例中使用端口8889:

ssh -L 8889:127.0.0.1:8889 username@linux-server.com

就像使用普通的SSH一样,您现在应该看到服务器的外壳(已经演示过)。现在,在同一终端中,cd到服务器的根web2py目录并执行以下(不要关闭终端窗口)

> cd mywebite.com
> python web2py.py -a password -i 127.0.0.1 -p 8889
*web2py startup stuff*

现在,在您的本地浏览器上访问http://127.0.0.1:8889/admin,您应该会看到服务器上的web2py管理页面。

  

B计划 - 使用自签名SSL证书

如果您仍然遇到ssh隧道问题,您可以尝试的另一个选项是使用自签名SSL证书。

使用OpenSSL制作自签名证书非常简单,您也可以使用一些online自签名证书生成器(虽然我不建议这样做)为您节省更多时间。

生成 .crt .key 文件后,将sftp发送到服务器并将文件上传到服务器的根web2py目录(或上传它们到Dropbox,ssh到你的服务器,cd到你的根web2py目录并忘记文件链接)。最后ssh到你的服务器并执行以下(不要关闭终端窗口)

> cd mywebite.com
> python web2py.py -a password -p 8889 -i 0.0.0.0 server.crt -k server.key
*web2py startup stuff*

现在在您的浏览器上输入(注意https) https://xxx.xxx.xxx.xxx:8889/admin(xxx ...作为您的服务器IP),或者如果您已经拥有您的服务器,则可以执行https://mywebsite.com:8889/admin域名设置。

现在您应该在浏览器上看到SSL安全警告。只需忽略此警告并添加例外,最后您就可以从服务器上看到web2py管理页面。

  

计划C - 编辑web2py源

这是允许管理员使用不安全通道的最不推荐的计划,应该作为最后的手段使用。您只需添加一行代码,即可编辑禁用管理员的web2py源代码部分。在 < 服务器的根web2py目录> \ applications \ admin \ models \ access.py(第21行)在禁用管理员的部分之前放置 request.is_local = True 不安全的渠道:

'...'
request.is_local=True #TESTING ONLY. COMMENT OUT OR REMOVE IN PRODUCTION!
if request.env.http_x_forwarded_for or request.is_https:
    session.secure()
elif not request.is_local and not DEMO_MODE:
    raise HTTP(200, T('Admin is disabled because insecure channel'))
'...'

现在,只需访问http://xxx.xxx.xxx.xxx:8889/admin(xxx ...作为您的服务器IP)即可访问服务器的web2py管理员,或者如果您已经设置了域名,则可以http://mywebsite.com:8889/admin

请注意,这是一个快速而肮脏的解决方案,只能暂时使用并进行测试。不要忘记在生产中删除或注释掉该行!

相关问题