开发者

Method Not Allowed when connecting to ssh host through Apache proxy

I'm trying to establish a ssh tunnel trough an HTTP proxy.

When testing the setup using a squid localhost proxy I'm receiving a "Method Not Allowed" from (I guess) the Apache remote proxy:

$ 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

This is my Apache virtual host config:

<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>

Any ideas? How to read the body of that 405 response to be sure it is coming from the remote Apache proxy in instead of the local squid proxy?

EDIT:

The request lands in the default server log:

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-cac开发者_如何学编程he"

New EDIT:

Making the proxy virtual server the default server makes it work !!!:

$ 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

What is happening here? Some proxytunnel bug?

EDIT:

It is not proxytunnel's fault. The same happens when telneting to connect:

$ 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.

Now move the config file to aaa.torno.example.com.conf to make it the default and it works:

$ 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


You see "Server: Apache/2.2.15 (CentOS)" header in 405 response, so if you use Squid, then the response must be coming from the server.

On a side note, I'd put this question to ServerFault rather than here.


Method not allow because proxytunnel is not supporting HTTP/1.1 in the binary release.

You may move part out of VirtualHost.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜