はじめに
catapultのAPIは、ポート3000で動作するようになりました。
ですが、httpsには対応していません。既に、多くのhttpsプロキシが世には存在しているので、おそらく対応されないと思います。
今回は、3001番ポートで受け付け、3000番ポートへプロキシするように設定してみます。
ソフトはnginx、証明書は、Let's Encryptを使います。
環境
OS
- Amazon Linux
開放しておくport
- 80 (証明書更新用)
- 3000 (http用)
- 3001 (https用)
proxyソフト
- nginx
ssl 証明書取得
- certbot (webroot方式)
手順
まずは、ドメインを取得して、ドメイン名とIPアドレスを関連付けましょう。
次に、サーバーにログインします。
rootになります。
sudo su
nginxをインストールして立ち上げて、自動起動をオンにします。
yum install nginx
service nginx restart
chkconfig nginx on
certbotをダウンロードして、証明書を取得します。<your ...>
のところは適宜かえてください。
cd <your favorit path>
git clone https://github.com/certbot/certbot
cd certbot/
./certbot-auto --help
./certbot-auto certonly --webroot -w /usr/share/nginx/html -d <your domain> -m <your mail address> --agree-tos -n --no-bootstrap
成功すると、なんかこんな感じのメッセージが出ると思います。
Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/<your domain>/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/<your domain>/privkey.pem
fullchain.pem
とprivkey.pem
をnginxに設定していきます。
vi /etc/nginx/nginx.conf
最後の箇所にこれ追加します。<your ...>
のところは適宜かえてください。
server {
listen 3001 ssl http2 default_server;
server_name _;
ssl_certificate /etc/letsencrypt/live/<your domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<your domain>/privkey.pem;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES25
6-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
location /ws {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:3000/ws;
}
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
設定の構文チェックをします。
nginx -t
問題なければOKと言われます。
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
設定を読み込みます。
nginx -s reload
これで、3001番ポートでアクセスできるようになりました。
最後に、証明書の有効期間は30日なので、自動更新するように設定します。
まずは、自動更新コマンドのテストをします。
<your path>/certbot-auto renew --dry-run
こんな感じのが出たら、成功です。
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/<your domain>/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
このコマンドをcronなどに登録します。
crontab -e
0 0,12 * * * sleep `expr $RANDOM \% 3600` && <your path>/certbot-auto renew && nginx -s reload
おわりに
nginxの設定ファイルは、ディストリビューションやバージョンで名前や場所が変わったりしているので、いろんな人の記事を参考にしてみるとよいと思います。
NIS1でも同じような手順でできます。
NISでstunnel4での手順 https://blog.nem.io/https-nis-node/