安裝 apache let's encrypt ssl 憑證

Brave Ye
系統管理員
Posts: 6294
Joined: 2025-11-08, 05:32
Location: Taiwan

安裝 apache let's encrypt ssl 憑證

Post by Brave Ye »

sudo apt update
sudo apt install certbot python3-certbot-apache -y

nano /etc/apache2/sites-available/default-ssl.conf
# line 2 : change admin email
ServerAdmin webmaster@srv.world
先按住ctrl鍵再按英文o鍵存檔
sudo a2ensite default-ssl
sudo a2enmod ssl
systemctl restart apache2


處理http://自動轉https://
nano /etc/apache2/sites-available/virtual.host.conf
<VirtualHost *:80> DocumentRoot /var/www/html ServerName zine-tw.com ServerAdmin youremail@mail.com ErrorLog /var/log/apache2/virtual.host.error.log CustomLog /var/log/apache2/virtual.host.access.log combined RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </VirtualHost>

sudo a2enmod rewrite
systemctl restart apache2

sudo certbot --apache
驗證systemd timer 自動續期
sudo certbot renew --dry-run