前回、Fess 13.1.0をインストールしました。
CentOS 7にFess 13.1.0をインストールしました
ですが、呼び出し元がhttpsなので、呼び出し先がhttpのままでは、FessのAPIが呼び出せません。
有料のSSLでも良かったのですが、重要な情報を扱ってないですし、Let’s Encryptでいいかということに。
https://letsencrypt.org/
というわけで、今回は、無料のSSL証明書「Let’s Encrypt」で、Fessをhttps化します。Fessの公式を見ると、「Fessをhttpsにするなら、Apacheでhttps化してから、リバースプロキシー設定してね」的なことが書かれていたのでそうします。
ドメインの取得
ドメインが無いと、SSL証明書を取得できないので、ドメインを取得しましょう。サブドメインでも可能です。今回、私は、サブドメインを取得してそちらを設定してもらいました。
certbotのインストール
参考:Let’s EncryptでApacheをHTTPSに対応させる
certbotが必要なのでインストールします。
$ yum -y install certbot python-certbot-apache
※epel-releaseが必要
まずは、http/httpsポートを許可しておきます。
$ firewall-cmd --list-all --permanent
$ firewall-cmd --add-service=https --permanent
$ firewall-cmd --add-service=http --permanent
$ firewall-cmd --reload
Apache起動・・・の前にhttpd.confにヴァーチャルホストでポート80を開ておきます。
そうしないと、以下のようなエラーが出てcertbotでのSSL証明書が成功しません。
Unable to find a virtual host listening on port 80 which is currently needed for Certbot to prove to the CA that you control your domain. Please add a virtual host for port 80.
httpd.confを編集
$ vi /etc/httpd/conf/httpd.conf
最下行に以下を追加
NameVirtualHost *:80
ServerAdmin [メールアドレス]
DocumentRoot /var/www/html
ServerName [ドメイン(サブドメインも可能)]
Apache起動
$ systemctl start httpd
一応、ブラウザでアクセスできるか確認しておきます。問題なければ、certbotでSSL認証を取得します。
certbotでSSL認証取得
$ certbot --apache [ドメイン(サブドメインも可能)]
–apacheは、apacheの設定ファイルを書き換えてくれるようです。
途中で、httpをhttpsにリダイレクトするようにするか聞かれるので、お好きな方を選択してください。
実際は、試行錯誤していて、すんなりいかなかったですが、うまくいけば上記の流れで取得完了です。
ちなみに、試行錯誤していたせいでcertbotで失敗し続けていると、下のようなエラーがでました。
$ certbot --apache -d ドメイン
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Obtaining a new certificate
An unexpected error occurred:
There were too many requests of a given type :: Error creating new order :: too many failed authorizations recently: see https://letsencrypt.org/docs/rate-limits/
Please see the logfiles in /var/log/letsencrypt for more details.
書かれている通り、ページをみると、以下のように書いてありました。
There is a Failed Validation limit of 5 failures per account, per hostname, per hour. This limit is higher on our staging environment, so you can use that environment to debug connectivity problems.
バリデーションの失敗は、1アカウント、1ホスト、1時間につき5回とあります。
ひとまず、1時間以上経ってから行ったら問題なかったので、上記のようなエラーがでたら1時間以上待ちましょう。
自動更新を有効に
自動更新のためのcronを設定します。
$ vi /etc/cron.d/letsencrypt
以下の内容を記述
13 12 1 * * root certbot renew --post-hook "systemctl restart httpd"
Fessのhttps対応
ApacheでSSL化が済んだら、Apacheのリバースプロキシーを設定して、Fessに飛ばします。
$ vi /etc/httpd/conf/httpd.conf
以下の記述を記載
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyRequests Off
ProxyPass / http://xxx.xxxx.xxxx:8080/
ProxyPassReverse / http://xxx.xxxx.xxxx:8080/
xxx.xxxx.xxxxの部分は、自分のFess環境のドメインに合わせてください。ポートを変えている場合は、8080の部分も。
上記の設定の場合は、
https://xxx.xxxx.xxxx/ でアクセスした時に、実際は https://xxx.xxxx.xxxx:8080/ を表示している感じになります。
https://xxx.xxxx.xxxx/fess/を、https://xxx.xxxx.xxxx:8080/にしたいとかなると、ちょっと色々いじる必要が出てくるようなので、今回はしませんでしたが、それを行っている記事を見かけてので、「ルートディレクトリーをfessに飛ばしたく無い!」って人は、探してみてください。
Apacheの再起動
$ systemctl restart httpd
httpsのサイトから、FessのAPIを呼び出してみた所、無事に呼び出すことが確認でました。めでたしめでたし。