大网数据广告活动
服务器运维问答

Apache refuses HTTP CONNECT over SSL on non default virtual host

· 52CE 我爱测

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…

问题原文

原帖链接 · Maxime Rossini · CC BY-SA 3.0

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

已采纳解答

原帖链接 · Maxime Rossini · CC BY-SA 3.0

Also, the problem does not come from proxytunnel as the request is correctly forwarded to apache and is present in the server logs

This was wrong, proxytunnel does not support SNI in the version I use (latest commit from their repository as of the date of this post, so something a little ahead of 1.9.1 if I trust their release tags).

The consequence is that the vhost selected by apache is the default vhost, no matter which host I try to CONNECT to.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。