0
1

More than 3 years have passed since last update.

centos8apachでSSL化してみた

Posted at

※注意
最近メモ書きをマークダウンで書くので、
そのままQiitaに上げれるなぁと思い投稿してみました。
個人使用のサーバーで、
セキュリティーとかはあまり気にして書いてません。

###SSL証明書の導入手順(centos8 apach)

ファイアウォール設定

httpとhttpsの通信を許可

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
firewall-cmd --permanent --list-all

サーバーホスト名の設定

vi /etc/httpd/conf/httpd.conf
ServerNameを自分のドメイン名に変更

#ServerName www.example.com:80
ServerName www.selen.tokyo:80

Let's Encryptのインストール

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto

/etc/httpd/conf/httpd.confファイルの最後に以下を追記

#SSL導入のため追記
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin root@www.selen.tokyo
DocumentRoot "/var/www/html/selenreact/build"
ServerName www.selen.tokyo:80
</VirtualHost>

Let's Encrypt設定

/usr/local/bin/certbot-auto --apache

各質問に答えて入力
Congratulations!と出たら完了

のハズだったが、
私の環境の場合、成功ならず。
ページを確認すると、設定中のサーバーからの証明書になっていて、
いったん証明書の削除下記と

/usr/local/bin/certbot-auto delete -d www.selen.tokyo

SSL
下記のsslapachの設定ファイルを削除し、
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf/httpd-le-ssl.conf

httpd.confの

Include /etc/httpd/conf/httpd-le-ssl.conf

の部分を削除し、httpdの再起動できることを確認して、
shell
/usr/local/bin/certbot-auto --apache

をやり直すとSSL化できていた。


###自動更新
SSL証明書は約3ヶ月で有効期限が切れるので、更新を自動設定

更新コマンド

certbot-auto renew
# /bin/sh
cd /root
certbot-auto renew
# ログ出力設定(下記無くても可)
LOG_ERR=/err.log
exec 2>>$LOG_ERR
date>>certbot-auto.log

cronの設定をする。

crontab -e

下記を追記

0 0 1 * * /root/certbot.sh:w

ログ出力は場所と権限を変えたほうがいいんだろうなぁ...


Apache環境重要な設定値

SSLCertificateKeyFile:秘密鍵のファイルを指定
SSLCertificateFile:サーバー証明書のファイルを指定

Apache起動・再起動・停止

systemctl restart httpd

systemctl stop httpd

systemctl enable httpd

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1