Apache2 : SSL/TLS の設定2019/01/25 |
|
SSL/TLS の設定して、HTTPS による暗号化通信ができるように設定します。
|
|
| [1] | |
| [2] | SSLの設定です。 |
|
www:~ # a2enmod ssl www:~ # a2enmod -l actions alias auth_basic authn_core authn_file authz_host authz_groupfile authz_core authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl socache_shmcb userdir reqtimeout php7
www:~ #
vi /etc/apache2/listen.conf # 17行目:コメント解除 Listen 443
www:~ #
vi /etc/apache2/vhosts.d/default-ssl.conf # 新規作成
<VirtualHost *:443>
DocumentRoot "/srv/www/htdocs"
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCertificateFile /etc/letsencrypt/live/www.srv.world/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.srv.world/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/www.srv.world/chain.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/srv/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
systemctl restart apache2 |
| [3] | HTTP 通信も全て HTTPS へリダイレクトして Always on SSL/TLS とする場合は以下のようにそれぞれの Virtualhost 設定内へ記述します。下例のように httpd.conf に設定しない場合は、各ドキュメントルートの直下に [.htaccess] を配置して設定します。 |
|
www:~ # a2enmod rewrite www:~ # a2enmod -l actions alias auth_basic authn_core authn_file authz_host authz_groupfile authz_core authz_user autoindex cgi dir env expires include log_config mime negotiation setenvif ssl socache_shmcb userdir reqtimeout php7 rewrite
www:~ #
vi /etc/apache2/vhosts.d/defalt.site.conf
<VirtualHost *:80>
DocumentRoot /srv/www/htdocs
ServerName www.srv.world
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
www:~ # systemctl restart apache2 |
| [4] | Firewalld を有効にしている場合は HTTPS サービスの許可が必要です。なお、HTTPS は 443/TCP を使用します。 |
|
www:~ # firewall-cmd --add-service=https --permanent success www:~ # firewall-cmd --reload success |
| [5] | クライアントPC から Web ブラウザでテストページに HTTPS でアクセスします。 正常にページが表示されれば OK です。Always On SSL/TLS を設定した場合は HTTP アクセスして正常にリダイレクトされるかも確認しておきます。 |
|
| Sponsored Link |
|
|