Ubuntu Apache2.4 でhttps で接続するために、SSL証明書の設定を行います。
ここでは、無料のLet’ Encript の証明書を発行します。certbotを使用すると、その証明書の設定、自動更新を自動でやってくれます。
こちらのサイトを参考に設定します。

- さくらVPS
 - Ubuntu22.04
 - Apache2.4.52
 
さくらVPSから与えられたドメインではできません。独自ドメインを取得する必要があります。
Certbotインストール
インストール
以下のコマンドでインストールします。
$ sudo apt install certbot python3-certbot-apache使用容量確認の質問がありました。Yを入力します。
再起動するサービスについて聞かれました。OKとします。

実行
certbotの実行をします。以下のコマンドを入力します。
$ sudo certbot --apache途中の質問内容
- メールアドレス
 - 承諾書の確認
 - メール受信の確認
 - ドメイン名
 
ドメイン名の設定は、独自で取得したものを入力しました。
証明書の自動更新
certbotは自動で証明書の更新をやってくれるようです。なのでここでは特に設定はしません。
Let’s Encriptは3か月ごとに証明書の更新をする必要があり、以前は自動更新の設定を手動でやっていました。
動作確認
動作確認をします。https://ドメイン名 でブラウザからアクセスしてみます。
表示されていることを確認しました。

2017年頃と比べて、ずいぶん設定が楽になったという印象です。
Apache2.4 の変更点
インストールすると、Apache2.4 の設定ファイルが自動的に更新されます。
000-default.conf
Apache2.4 の/etc/apache2/sites-available の000-default.conf が自動で更新されました。http://ドメイン名でアクセスした場合は、https;//ドメイン名 にリロードされる設定となりました。
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} ='ドメイン名"
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
000-default-le-ssl.conf
同ディレクトリに、000-default-le-ssl.conf が追加されています。https で接続した場合は、この設定ファイルが適用されます。
<IfModule mod_ssl.c>
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
ServerName ’ドメイン名’
SSLCertificateFile /etc/letsencrypt/live/’ドメイン名’/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/’ドメイン名’/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
000-default-le-ssl.conf のleは、Let’s Encript の略と思います。


			
			
			
			
			
			
			
			
コメント