1, 首先申請一張SSL , 我自己就在ZeroSSL https://zerossl.com/ 申請 SSL Cert.
2, 安裝openssl
sudo apt-get install openssl
3, 啟用Apache的SSl模組
sudo a2enmod ssl
4, 建立憑證資料夾,並建立認證(自簽憑證 這次不適用)
sudo mkdir /etc/apache2/ssl
((自簽憑證 這次不適用))
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
-days 後面的參數365是憑證的有效日期
-out 和 –keyout 是憑證和金鑰產出後要存放的路徑。
-x509 refers to the X.509 standard,
while rsa:2048 refers to 2048-bit RSA cryptosystem (cryptographic algorithms).
5, 建立連結
sudo ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/000-default-ssl.conf
6, 編輯SSL設定檔
sudo nano /etc/apache2/sites-enabled/000-default-ssl.conf
確定設定中:
ServerAdmin admin@domain.com
DocumentRoot /var/www/
ServerName www.domain.com
ErrorLog /www/home/logs/error_log
SSLEngine on
SSLCertificateFile /etc/ssl/certificate.crt
SSLCertificateKeyFile /etc/ssl/private.key
SSLCertificateChainFile /etc/ssl/ca_bundle.crt
7, 重啟Apache
設定好 Apache 的 SSL config 次後,就把 Apache 重啟來讓新設定生效,請下面的指令來重新啟動 Apache。
sudo service apache2 restart