apacheを使ってhttpsを設定・運用していたが、なにか設定を触った時に、http+let’s encryptで使っている鍵が合わないと表示されapacheが起動しなくなっていた。certbotで鍵を作り替えたり、apacheの設定を見直してみたが、原因わからず、結局web serverをapache2からnginxに切り替えることにした。
apache2の自動起動を止める。
# systemctl disable apache2
nginxをinstall
$ sudo apt-get install nginx
設定する。
sslはcertbotで作成済みなので、流用する。
vi /etc/nginx/sites-enabled/default
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name domain_name;
root /var/www/html;
ssl_certificate /etc/letsencrypt/live/domain_name/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain_name/privkey.pem;
index index.html index.htm index.php index.nginx-debian.html;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
location / {
try_files $uri $uri/ =404;
}
}
nginxを再起動
$ sudo service nginx restart