環境
Ubuntu20.04
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 1.1.1f 31 Mar 2020
問題
let’s encriptのSSL証明書は3ヶ月であり、期限が切れてしまっていた。
有効期限が切れてしまうと
$ sudo certbot renew
をしてもうまくいかない。
解決策
有効期限が切れてしまった場合はまた1から証明書を作成する必要がある。
$ sudo certbot --nginx -d {ドメイン名}
と入力する。私のサイトでは
$ sudo certbot --nginx -d tsubame.0am.jp
となる。
証明書を作成したのに保護されない場合
良くある原因
まず良くある原因としてはnginxの設定ファイルで証明書のパスの指定が記述されていないことです。
設定ファイルの記述は/etc/nginx/conf.d/ssl.conf
に行います。
server {
listen 443 ssl;
server_name tsubame.0am.jp www.tsubame.0am.jp;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
ssl_certificate /etc/letsencrypt/live/tsubame.0am.jp/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/tsubame.0am.jp/privkey.pem;
error_page 404 https://tsubame.0am.jp;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
location ^~ /index.html {
return 301 http://tsubame.0am.jp/itotakublog/index.php$query_string;
}
}
server {
# httpをhttpsにリダイレクト
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
# SSLを無効化してTLSのみ受け付ける
ssl_protocols TLSv1.2 TLSv1.3;
}
私の場合
私のサイトではURLが間違っていた場合、全てホームページにリダイレクトするようにしているのですが、その時に80ポートもリッスンしているとhttpの方にリダイレクトされてしまうことがあるみたいです。
よって/etc/nginx/conf.d/ssl.conf
の
listen 80
をコメントアウトすることで解決できました。
最近のコメント