CentOS 7 + Nginx + rep2 で HTTPS & HTTP/2化

最近のブラウザーは、httpではなくhttpsでないと
危険なサイト扱いされて表示そのものが出来無くなってくるとの事で
rep2サイトもHTTPS化を実行


ついでにHTTP/2化も同時に実施する
HTTP/2は規格としてはHTTPSとは別立てで、HTTP Server側で一言設定を入れることでHTTPSとは別に設定が可能だが
ChromeFirefoxSafariのブラウザ側の実装として、HTTP/2はHTTPSとセットになっていないとデコードできない現実がある
その為 HTTP/2の前提条件として、HTTPSの実装が必要になる


SSL証明書については、無料の Let's Encryptを使用するとして
certbotを使用すると秘密鍵生成まで自動してくれる


Let's Encryptの非公式日本語解説サイトもあるので、一通り読んでおくと良い
(但し情報が古すぎてイマイチ使えないのだが)


CentOSの場合、EPELリポジトリcertbot パッケージが格納されているので
EPELリポジトリを導入するが、通常EPELリポジトリは導入しているのでスキップ


ちなみに今回
自宅サーバーなので、HTTPS化を実施した場合、HTTPSのPortだけ開放してHTTPのポートを閉じようと考えている
Webの色々なやり方を見ていると、HTTPSだけポート開放した例が見当たらなかったので
更新の時に試行錯誤しような予感・・・

# yum install certbot

certbot パッケージと依存関係のあるパッケージ 40個程インストール


certbotのVerは結構頻繁に変わっており、それに伴ってオプションも色々変更あるみたいなので
現行のVer(0.24.0-1.el7)のOptionを確認

# certbot --help

-------------------------------------------------------------------------------

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

Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate. The most common SUBCOMMANDS and flags are:

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
    enhance         Add security enhancements to your existing configuration
   -d DOMAINS       Comma-separated list of domains to obtain a certificate for

  (the certbot apache plugin is not installed)
  --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
  --manual          Obtain certificates interactively, or using shell script
hooks

   -n               Run non-interactively
  --test-cert       Obtain a test certificate from a staging server
  --dry-run         Test "renew" or "certonly" without saving any certificates
to disk

manage certificates:
    certificates    Display information about certificates you have from Certbot
    revoke          Revoke a certificate (supply --cert-path)
    delete          Delete a certificate

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

More detailed help:

  -h, --help [TOPIC]    print this message, or detailed help on a topic;
                        the available TOPICS are:

   all, automation, commands, paths, security, testing, or any of the
   subcommands or plugins (certonly, renew, install, register, nginx,
   apache, standalone, webroot, etc.)
-------------------------------------------------------------------------------

こんな感じで実行すれば取り敢えず大丈夫かな
dry-runで試行

certbot certonly --dry-run --webroot --http-01-port 8080 -w <DocumentRoot> -d <Domain> -m <Mail Address>

HTTPのportを変更していたので、http-01-portオプションを指定したのだが、確かにcertbot は 8080でポート確認しているのに
アクセスしてきてるのがデフォルトの 80 とか
なんだ、このバカ仕様?


これじゃPort変更しているサイトは全てダメなんじゃないかと思ったり
という所で一旦終了


なんか素直に安い証明書調達したほうが楽な気がしてきた _no
なんだけど、mydns.jpだとそういうわけにもいかないしなあ


追記
サイトによっては、Nginx側にサーバーチェック用ディレクトリ設定を入れる必要があると記載がある

    location ^~ /.well-known/acme-challenge/ {
      root /usr/share/nginx/html/.well-known;

certbot実行中にディレクトリが作成されるのは確認していたけど、アクセス権の絡みで失敗していたんかな??
改めて後日検証してみるか