proxy - 通过Apache代理连接到ssh主机时不允许使用方法

标签 proxy ssh mod-proxy tunneling proxytunnel

我正在尝试通过HTTP代理建立ssh隧道。

当使用鱿鱼本地代理测试安装程序时,我从(我想)Apache远程代理收到“不允许的方法”:

$ proxytunnel -v -p localhost:3128 -r torno.example.com:80 -d ssh.example.com:22 -H "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache"
Local proxy localhost resolves to 127.0.0.1
Connected to localhost:3128 (local proxy)

Tunneling to torno.example.com:80 (remote proxy)
Communication with local proxy:
 -> CONNECT torno.example.com:80 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.0 200 Connection established

Tunneling to ssh.example.com:22 (destination)
Communication with remote proxy:
 -> CONNECT ssh.example.com:22 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.1 405 Method Not Allowed
HTTP return code: 405 Method Not Allowed
 <- Date: Thu, 25 Aug 2011 17:17:07 GMT
 <- Server: Apache/2.2.15 (CentOS)
 <- Allow: GET,HEAD,POST,OPTIONS,TRACE
 <- Content-Length: 352
 <- Connection: close
 <- Content-Type: text/html; charset=iso-8859-1

这是我的Apache虚拟主机配置:
<VirtualHost *:80>

     ServerAdmin admin@example.com
     ServerName torno.example.com
     ServerSignature Off

     HostnameLookups Off
     LogLevel Warn
     ErrorLog logs/torno.example.com-error_log
     CustomLog logs/torno.example.com-access_log combined

     ProxyRequests On
     AllowConnect 22

     <Proxy *>
         Order deny,allow
         Deny from all
     </Proxy>
     <Proxy ssh.example.com>
         Order deny,allow
         Allow from all
     </Proxy>

     ProxyPass / http://www.ibm.com/
     ProxyPassReverse / http://www.ibm.com/
     <Proxy http://www.ibm.com/>
         Order deny,allow
         Allow from all
     </Proxy>

</VirtualHost>

有任何想法吗?如何读取405响应的正文以确保它来自远程Apache代理而不是本地squid代理?

编辑:

该请求将进入默认服务器日志:
189.99.135.105 - - [25/Aug/2011:17:17:07 +0000] "CONNECT ssh.example.com:22 HTTP/1.0" 405 352 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\\nHost: ssh.example.com\\nContent-Length: 0\\nPragma: no-cache"

新的编辑:

将代理虚拟服务器设置为默认服务器可以使其正常工作!
$ proxytunnel -v -p localhost:3128 -r torno.example.com:80 -d ssh.example.com:22 -H "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache"
Local proxy localhost resolves to 127.0.0.1
Connected to localhost:3128 (local proxy)

Tunneling to torno.example.com:80 (remote proxy)
Communication with local proxy:
 -> CONNECT torno.example.com:80 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.0 200 Connection established

Tunneling to ssh.example.com:22 (destination)
Communication with remote proxy:
 -> CONNECT ssh.example.com:22 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.0 200 Connection Established
 <- Proxy-agent: Apache/2.2.15 (CentOS)

Tunnel established.
SSH-2.0-OpenSSH_5.3

这是怎么回事一些proxytunnel错误?

编辑:

这不是proxytunnel的错。通过远程登录进行连接时会发生相同的情况:
$ telnet torno.example.com 80
Trying 1.2.3.4...
Connected to torno.example.com.
Escape character is '^]'.
CONNECT ssh.example.com:22 HTTP/1.1
Host: ssh.example.com

HTTP/1.1 405 Method Not Allowed
Date: Fri, 26 Aug 2011 12:34:24 GMT
Server: Apache/2.2.15 (CentOS)
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Length: 352
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method CONNECT is not allowed for the URL /.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at <a href="mailto:admin@cz.example.com">ssh.example.com</a> Port 22</address>
</body></html>
Connection closed by foreign host.

现在将配置文件移动到aaa.torno.example.com.conf以使其成为默认文件,并且可以正常工作:
$ telnet torno.example.com 80
Trying 1.2.3.4...
Connected to torno.example.com.
Escape character is '^]'.
CONNECT ssh.example.com:22 HTTP/1.1
Host: ssh.example.com

HTTP/1.0 200 Connection Established
Proxy-agent: Apache/2.2.15 (CentOS)

SSH-2.0-OpenSSH_5.3

最佳答案

您会在405响应中看到“服务器:Apache / 2.2.15(CentOS)” header ,因此,如果您使用Squid,则响应必须来自服务器。

附带说明一下,我将把这个问题放到ServerFault而不是这里。

关于proxy - 通过Apache代理连接到ssh主机时不允许使用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7194876/

相关文章:

ruby - 如何让本地代理服务器将 html 返回到浏览器?

android - 带有用户/密码的 Genymotion 代理

bash:通过 ssh 并行执行命令

Apache 虚拟主机不适用于子域

https 站点的 Apache 反向代理给出 (70014) 找到文件结尾 :

maven - 如何配置 maven settings.xml 以访问 apache 代理背后的 nexus

javascript - 根据URL路径创建代理

C 套接字 : forward a request to port 80 and read response

python - Fab 未找到主机 key

git - git从6个月前开始继续推送错误的文件