web-dev-qa-db-ja.com

インストール後にSSL接続が拒否されました

Apache2とOpenSSLをインストールしました

私はOpenSSLを次のようにインストールしました:

Sudo a2enmod ssl

Sudo mkdir /etc/Apache2/ssl

Sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/Apache2/ssl/Apache.key -out /etc/Apache2/ssl/Apache.crt

Sudo chmod 600 /etc/Apache2/ssl/*

Sudo nano /etc/Apache2/sites-enabled/***.ru.conf

ファイルを構成した後

ファイル:/ etc/Apache2/sites-enabled/***。ru.conf

<VirtualHost *:80>

    ServerAdmin office@***.eu
    ServerName ***.ru
    ServerAlias www.***.ru
    DocumentRoot /var/www/***.ru/public_html
    ErrorLog ${Apache_LOG_DIR}/error.log
    CustomLog ${Apache_LOG_DIR}/access.log combined

</VirtualHost>
<VirtualHost *:443>

    ServerAdmin office@***.eu
    ServerName ***.ru:443
    ServerAlias www.***.ru
    DocumentRoot /var/www/***.ru/public_html
    ErrorLog ${Apache_LOG_DIR}/error.log
    CustomLog ${Apache_LOG_DIR}/access.log combined

    SSLEngine on
    SSLCertificateFile "/etc/Apache2/ssl/Apache.crt"
    SSLCertificateKeyFile "/etc/Apache2/ssl/Apache.key"

</VirtualHost>

# vim: syntax=Apache ts=4 sw=4 sts=4 sr noet

と再起動

Sudo /etc/init.d/Apache2 restart

Httpでドメインを正常に呼び出すことができます。しかし、httpsでは「接続が拒否されました」

私に何ができる?


アップデート1:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      21766/Apache2
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      12556/rpcbind
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21766/Apache2
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      402/sshd
tcp6       0      0 :::111                  :::*                    LISTEN      12556/rpcbind
udp        0      0 0.0.0.0:859             0.0.0.0:*                           12556/rpcbind
udp        0      0 0.0.0.0:111             0.0.0.0:*                           12556/rpcbind
udp6       0      0 :::859                  :::*                                12556/rpcbind
udp6       0      0 :::111                  :::*                                12556/rpcbind

アップデート2:

● Apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/Apache2)
  Drop-In: /lib/systemd/system/Apache2.service.d
           └─forking.conf
   Active: active (running) since Mon 2017-09-04 22:21:51 CEST; 32min ago
  Process: 21728 ExecStop=/etc/init.d/Apache2 stop (code=exited, status=0/SUCCESS)
  Process: 21752 ExecStart=/etc/init.d/Apache2 start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/Apache2.service
           ├─21766 /usr/sbin/Apache2 -k start
           ├─21769 /usr/sbin/Apache2 -k start
           ├─21794 /usr/sbin/Apache2 -k start
           └─21795 /usr/sbin/Apache2 -k start

Sep 04 22:21:50 86piub systemd[1]: Starting LSB: Apache2 web server...
Sep 04 22:21:51 86piub Apache2[21752]: Starting web server: Apache2.
Sep 04 22:21:51 86piub systemd[1]: Started LSB: Apache2 web server.

アップデート3:

[Mon Sep 04 21:06:04.445632 2017] [mpm_prefork:notice] [pid 20572] AH00163: Apache/2.4.10 (Debian) configured -- resuming normal operations
[Mon Sep 04 21:06:04.445676 2017] [core:notice] [pid 20572] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:16:36.199232 2017] [mpm_prefork:notice] [pid 20572] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:16:37.326606 2017] [mpm_prefork:notice] [pid 20736] AH00163: Apache/2.4.10 (Debian) configured -- resuming normal operations
[Mon Sep 04 21:16:37.326652 2017] [core:notice] [pid 20736] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:19:56.402621 2017] [mpm_prefork:notice] [pid 20736] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:19:57.547091 2017] [mpm_prefork:notice] [pid 20815] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 21:19:57.547136 2017] [core:notice] [pid 20815] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:28:37.135554 2017] [mpm_prefork:notice] [pid 20815] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:36:24.963288 2017] [ssl:warn] [pid 21088] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:36:24.992551 2017] [ssl:warn] [pid 21089] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:36:24.993230 2017] [mpm_prefork:notice] [pid 21089] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 21:36:24.993245 2017] [core:notice] [pid 21089] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:36:42.013201 2017] [mpm_prefork:notice] [pid 21089] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:36:43.125758 2017] [ssl:warn] [pid 21140] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:36:43.150716 2017] [ssl:warn] [pid 21141] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:36:43.151416 2017] [mpm_prefork:notice] [pid 21141] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 21:36:43.151450 2017] [core:notice] [pid 21141] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:37:42.229356 2017] [mpm_prefork:notice] [pid 21141] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:37:43.345401 2017] [ssl:warn] [pid 21195] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:37:43.371558 2017] [ssl:warn] [pid 21196] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:37:43.372641 2017] [mpm_prefork:notice] [pid 21196] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 21:37:43.372667 2017] [core:notice] [pid 21196] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:40:15.942263 2017] [mpm_prefork:notice] [pid 21196] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:40:17.047285 2017] [ssl:warn] [pid 21288] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:40:17.071700 2017] [ssl:warn] [pid 21289] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:40:17.072403 2017] [mpm_prefork:notice] [pid 21289] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 21:40:17.072419 2017] [core:notice] [pid 21289] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 21:51:43.059740 2017] [mpm_prefork:notice] [pid 21289] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 21:51:44.171087 2017] [ssl:warn] [pid 21424] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:51:44.198683 2017] [ssl:warn] [pid 21425] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 21:51:44.199380 2017] [mpm_prefork:notice] [pid 21425] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 21:51:44.199404 2017] [core:notice] [pid 21425] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 22:13:38.102014 2017] [mpm_prefork:notice] [pid 21425] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 22:13:39.213574 2017] [ssl:warn] [pid 21646] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 22:13:39.240219 2017] [ssl:warn] [pid 21647] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 22:13:39.240929 2017] [mpm_prefork:notice] [pid 21647] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 22:13:39.240948 2017] [core:notice] [pid 21647] AH00094: Command line: '/usr/sbin/Apache2'
[Mon Sep 04 22:21:49.629640 2017] [mpm_prefork:notice] [pid 21647] AH00169: caught SIGTERM, shutting down
[Mon Sep 04 22:21:50.728557 2017] [ssl:warn] [pid 21765] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 22:21:50.751995 2017] [ssl:warn] [pid 21766] AH01906: ***.ru:443:0 server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Sep 04 22:21:50.752633 2017] [mpm_prefork:notice] [pid 21766] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Mon Sep 04 22:21:50.752650 2017] [core:notice] [pid 21766] AH00094: Command line: '/usr/sbin/Apache2'

アップデート4:

openssl s_client -connect ***.ru:443 -tls1 -servername ***.ru | openssl x509 -text -noout

教えてくれます

connect: Connection refused
connect:errno=111
unable to load certificate
140019880523408:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: TRUSTED CERTIFICATE
2
Bernhard

したがって、問題は、SSL証明書がサーバーとして使用される証明書ではなくCA証明書として解釈されていることです。これに対する簡単な解決策は、CA証明書を生成し、それを使用してサーバーの証明書を作成することです。

openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -days 10000 -out ca.crt
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=IP-OR-DOMAIN-HERE" -out server.csr
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -out server.crt -days 10000

次に、生成されたserver.crtおよびserver.keyをApache用に使用できます。

ただし、自己署名証明書を使用していることに注意してください。最近では無料で信頼できる証明書を取得できることを考えると、 Certbot のようなものを調べることを強くお勧めします。

2
ConnorJC