今日びのWebsiteはhttpsじゃないとダメとかいわれているので、別サーバ(FreeBSD12.1のルータ)にインストールしたnginxでリバースプロキシを動かしつつ、Let's Encryptでhttps化を試みる。
インストール
pkgでnginx-liteとpy37-certbot-nginxをインストールする。
>pkg install nginx-lite >pkg install py37-certbot-nginx
Let's Encryptの設定
基本的には毎日防備録に書いてある通り。ただし、最初の"How would you like to authenticate with the ACME CA?"という質問については、"1: Nginx Web Server plugin (nginx)"を選択した。
証明書の取得に成功したら、/etc/periodic.confにweekly_certbot_enable="YES"を追加する。
nginxの設定
@HeRo氏によるQiita: Let's Encrypt で Nginx にSSLを設定すると、久保達彦、道井俊介『nginx実践入門』(技術評論社)を参考にして、nginxの設定ファイル /usr/local/etc/nginx/nginx.conf の server { … } を以下のように設定した。
server { listen 80; server_name www.ktjdragon.com; location /{ return 301 https://ktjdragon.com$request_uri; } } server { listen 443 ssl; server_name ktjdragon.com; ssl_certificate /usr/local/etc/letsencrypt/live/ktjdragon.com/fullchain.pem; ssl_certificate_key /usr/local/etc/letsencrypt/live/ktjdragon.com/privkey.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { client_max_body_size 8m; client_body_buffer_size 16k; client_body_temp_path /usr/local/www/nginx_client_body_temp; proxy_buffering on; proxy_buffer_size 8k; proxy_buffers 64 8k; proxy_max_temp_file_size 1024m; proxy_temp_path /usr/local/www/nginx_proxy_temp; proxy_connect_timeout 5s; proxy_send_timeout 10s; proxy_read_timeout 10s; proxy_pass http://Bottleが動いているサーバのipアドレス; } }
やっていることは以下の通り。
これまでのURLである"http://www.ktjdragon.com/〜"は"https://ktjdragon.com/〜"にリダイレクト
"https://ktjdragon.com/〜"をBottleが動いているサーバにリバースプロキシ
(2020/5/24追記) リバースプロキシで404エラーが出るとBottle側のURLが出てしまうことに気づいた。とりあえずチュートリアル通りに簡単なエラーページに差し替えるようにした。