DokuWikiで情報発信

個人での情報発信や社内での情報共有に便利なDokuWikiを紹介するサイトです。

ユーザ用ツール

サイト用ツール


サイドバー

目次

DokuWikiを理解

DokuWikiの構築

よく確認するページ

Action disabled: source
· 最終更新: 2023/07/12 by oreda admin



「サーバ準備」に戻る

Let's Encryptの無料SSL証明書を使ってhttps暗号化通信

概要

Webrootプラグイン
Certbot クライアントを実行するコンピュータでウェブサーバ(httpd)が動作中であり、ウェブサーバを停止することなく SSL/TLS 証明書を発行したい場合には、Webroot プラグインをご利用ください。
Webroot プラグインは、コマンドラインオプションで certonly と –webroot を指定することで使用可能です。

https://letsencrypt.jp/docs/using.html


Let's Encryptのコマンド準備

RHEL/CentOS 7

# yum install epel-release
# yum install certbot

Ubuntu

# apt install certbot


コマンドの確認

# certbot -h

  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

obtain, install, and renew certificates:
    (default) run   Obtain & install a certificate in your current webserver
    certonly        Obtain or renew a certificate, but do not install it
    renew           Renew all previously obtained certificates that are near

expiry
   -d DOMAINS       Comma-separated list of domains to obtain a certificate for

  --standalone      Run a standalone webserver for authentication
  (the certbot nginx plugin is not installed)
  --webroot         Place files in a server's webroot folder for authentication

   -n               Run non-interactively

  --dry-run         Test "renew" or "certonly" without saving any certificates to disk

manage your account with Let's Encrypt:
  --agree-tos       Agree to the ACME server's Subscriber Agreement
   -m EMAIL         Email address for important account notifications


証明書の生成

ドメインごとに行う処理です。

Nginxの例

# certbot certonly --webroot -w /var/www/html/example.com/dokuwiki/ -d example.com -m yourmail@gmail.com --agree-tos

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for network.oreda.net
Using the webroot path /var/www/html/example.com/dokuwiki for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2018-03-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

この例では、以下の2つの鍵が作られます。この鍵をApacheやnginxの設定で読み込みましょう。
/etc/letsencrypt/live/example.com/fullchain.pem
/etc/letsencrypt/live/example.com/privkey.pem

  • --webroot : 動かしているWebサーバ(AapcheかNginx)を利用して、ドメインの確認をする方法です。
    • --standaloneにすると、一時的にLet's EncryptのWebサーバを起動しドメインを確認しますが、既にWebサーバが起動していると利用できません。
  • -w : ディレクトリにtest.htmlを作成すると、http://example.com/test.html でアクセスすると表示できるディレクトリ
    • 例:/var/www/html/test.html
注意
  • ファイアウォールやBasic認証などでアクセス制御していると、コマンドが失敗します。


証明書の更新設定

土曜の22時に更新するようにします。

0 22 * * 6 certbot-2 renew | systemctl restart nginx

参考

特定のドメインのみ更新
certbot certonly --standalone -d FQDN
certbot certonly --standalone -d example.com
有効期限が30日未満のすべてのドメインを更新
certbot renew
すべてのドメインを強制的にすべて更新
certbot renew --force-renewal


証明書が不要になった時の作業

証明書を失効させる
# certbot-auto revoke --cert-path=/etc/letsencrypt/archive/example.com/cert1.pem
関係ディレクトリ、ファイルの削除か移動
# rm -rf /etc/letsencrypt/archive/example.net.conf
# rm -rf /etc/letsencrypt/live/example.net
# rm -rf /etc/letsencrypt/renewal/example.net.conf




Apache httpサーバのSSL設定方法

設定

設定ファイル例 :/etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem


NginxのSSL設定方法

設定

設定ファイル例 : /etc/nginx/conf.d/xxxxx.conf

server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ;
    server_name example.com;

    ssl on;
    ssl_certificate      /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;  

    (略)
}

セキュリティーのために以下も追加しましょう。

    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets on;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
設定反映
# systemctl reload nginx   <- Nginxの設定反映
設定反映
# lsof -i :443             <- 追加したいポートが既に利用されていないか確認
# nginx -t                 <- 設定の確認
# systemctl reload httpd   <- Nginxの設定反映
# lsof -i :443             <- 追加したいポートがあがっていることを確認


Let's Encryptを利用している場合のサーバ移行

旧サーバ

certbot-2 renew    <- 念のため証明書の更新をしておきましょう。
cd /etc
tar cvzf letsencrypt_back.tar.gz letsencrypt   <- バックアップ

更新のcronを停止

新サーバ

mv /etc/letsencrypt /etc/letsencrypt.org
tar zxf letsencrypt_back.tar.gz -C /etc


##ディレクトリが変更となっている場合更新
vi /etc/letsencrypt/renewal/example.com.conf
example.com = /usr/share/nginx/html/example/dokuwiki


更新のcronを開始





「サーバ準備」に戻る




· 最終更新: 2023/07/12 by oreda admin

ページ用ツール