I have an apache 2.4.18 server running with multiple vhosts.
/etc/apache2/sites-enabled/000-default.conf:
<VirtualHost *:80>
DocumentRoot /var/www/html
Redirect 400 /
</VirtualHost>
/etc/apache2/sites-enabled/000-default-ssl.conf:
<VirtualHost _default_:443>
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
/etc/apache2/sites-enabled/001-custom.conf:
<VirtualHost _default_:443>
ServerName www.example.org
Include /etc/apache2/letsencrypt/main.conf
SSLCertificateFile /etc/letsencrypt/live/example.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.org/privkey.pem
Include /etc/apache2/proxytunnel/main.conf
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.org
Redirect permanent / https://www.example.org/
</VirtualHost>
/etc/apache2/proxytunnel/main.conf:
ProxyRequests On
AllowConnect 2222
<Proxy *>
Order deny,allow
Deny from all
</Proxy>
<Proxy 127.0.0.1>
Order deny,allow
Allow from all
</Proxy>
I also have a running SSH server running on port 2222 of the same machine.
If I use proxytunnel from a remote machine to access the SSH server over SSL, using apache as the proxy server:
proxytunnel -v -E -p www.example.org:443 -d 127.0.0.1:2222
I get the following error:
SSL client to proxy enabled
Local proxy www.example.org resolves to xxx.xxx.xxx.xxx
Connected to www.example.org:443 (local proxy)
Tunneling to 127.0.0.1:2222 (destination)
Communication with local proxy:
-> CONNECT 127.0.0.1:2222 HTTP/1.1
-> Host: 127.0.0.1:2222
-> Proxy-Connection: Keep-Alive
<- HTTP/1.1 405 Method Not Allowed
HTTP return code: 405 Method Not Allowed
<- Date: Thu, 14 Apr 2016 00:55:57 GMT
<- Server: Apache/2.4.18 (Debian)
<- Allow: GET,HEAD,POST,OPTIONS
<- Content-Length: 309
<- Content-Type: text/html; charset=iso-8859-1
But if I include the file /etc/apache2/proxytunnel/main.conf
in my /etc/apache2/sites-enabled/000-default-ssl.conf
vhost, it works...
SSL client to proxy enabled
Local proxy www.example.org resolves to xxx.xxx.xxx.xxx
Connected to www.example.org:443 (local proxy)
Tunneling to 127.0.0.1:2222 (destination)
Communication with local proxy:
-> CONNECT 127.0.0.1:2222 HTTP/1.1
-> Host: 127.0.0.1:2222
-> Proxy-Connection: Keep-Alive
<- HTTP/1.0 200 Connection Established
<- Proxy-agent: Apache/2.4.18 (Debian)
Tunnel established.
SSH-2.0-OpenSSH_7.2p2 Debian-2
So my conclusion is that for a CONNECT request to work through an apache server over SSL, the AllowCONNECT
directive must be placed in the default vhost for the apache proxy port in addition to the actual vhost the request is made.
Note that the behavior is not reproduced when using CONNECT over HTTP (instead of HTTPS) and encryption is disabled in proxytunnel. Also, the problem does not come from proxytunnel as the request is correctly forwarded to apache and is present in the server logs: it is apache that actively refuses it because it considers the HTTP method (CONNECT) invalid on this server (although it is allowed in the vhost which is concerned).