Apache 提供 HTTP 而非 HTTPS

Apache 提供 HTTP 而非 HTTPS

我最近从 Apache 2.2 升级到了 2.4(我知道,我升级很慢,不要恨我)。我有以下虚拟主机:

<VirtualHost _default_:30000>
    DocumentRoot /opt/phpmyadmin
    ErrorLog ${APACHE_LOG_DIR}/error.log

    <Directory /opt/phpmyadmin>
        Options -Indexes +IncludesNOEXEC +FollowSymLinks
        Require all granted
    </Directory>
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    LogLevel warn
</VirtualHost>

之前使用Allow from all语法时,HTTPS 可以完美运行在端口 443 上的其他虚拟主机上。但是,当我访问 时https://localhost:30000,它提供 HTTP 内容而不是 HTTPS。这也是唯一使用端口 30000 的虚拟主机,因此我假设这不是由于与其他优先虚拟主机发生冲突而导致的。

HTTPS 请求:

$ curl -v https://localhost:30000
* Rebuilt URL to: https://localhost:30000/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 30000 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Closing connection 0
curl: (35) error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

然后这会在 Apache 访问日志中生成以下内容:

127.0.0.1:80 XXX.XXX.XXX.149 - - [04/Oct/2021:13:14:37 -0400] "\x16\x03\x01\x02" 400 0 "-" "-"

HTTP 请求

$ curl -v http://localhost:30000
* Rebuilt URL to: http://localhost:30000/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 30000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: localhost:30000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Mon, 04 Oct 2021 16:47:46 GMT
* Server Apache is not blacklisted
< Server: Apache
< Vary: Accept-Encoding
< Content-Length: 481
< Content-Type: text/html;charset=UTF-8
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /</title>
 </head>
 <body>
<h1>Index of /</h1>
  <table>
   <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
   <tr><th colspan="5"><hr></th></tr>
</table>
</body></html>

编辑:

我刚刚注意到一件事。我已经-Indexes设置了,但返回的 HTTP 内容是目录索引。所以我想也许有人以某种方式使用了另一个虚拟主机。我仍然不知道这是怎么可能的,因为这是唯一一个使用端口 30000 的虚拟主机。

答案1

好的,我解决了我的问题。我之前使用的是/etc/apache2/sites-enabled/domain,但我需要将其更改为/etc/apache2/sites-enabled/domain.conf

答案2

就我而言,默认的虚拟主机<VirtualHost _default_:443>缺少证书,因此我使用 certbot 启用了证书,然后错误\x16\x03\x01\x02就解决了。

相关内容