關閉      標題:linux godaddy ssl apache 設定懶人包
內容:

Apache SSL 安裝懶人筆記(GoDaddy)
1. 拿到的檔案

憑證商提供:

c30f7b44c76fb4be.crt
c30f7b44c76fb4be.pem
gd-g2_iis_intermediates.p7b
私鑰:
generated-private-key.txt

2. 建議建立 SSL 目錄
/etc/apache2/ssl/

建立:

mkdir /opt/ssl_certs
3. 整理憑證檔名
cp generated-private-key.txt /opt/ssl_certs/focusit_tw.key
cp c30f7b44c76fb4be.crt /opt/ssl_certs/focusit_tw.crt
cp gd-g2_iis_intermediates.p7b /opt/ssl_certs/
設定權限:
chmod 600 /opt/ssl_certs/focusit_tw.crt

4. 轉換 p7b → pem

Apache 不吃 p7b,需要轉成 pem:

openssl pkcs7 -print_certs -in /opt/ssl_certs/gd-g2_iis_intermediates.p7b -out /opt/ssl_certs/gd_bundle.pem

. 建立 fullchain(推薦)
cat /opt/ssl_certs/focusit_tw.crt /opt/ssl_certs/gd_bundle.pem > /opt/ssl_certs/fullchain.pem


6. 確認 key 與 cert 相符

cert:
openssl x509 -noout -modulus -in /opt/ssl_certs/focusit_tw.crt | openssl md5

key:
openssl rsa -noout -modulus -in /opt/ssl_certs/focusit_tw.key | openssl md5


7. 開啟 Apache SSL module
a2enmod ssl

建議同時開:

a2enmod rewrite
a2enmod headers
8. 啟用 SSL site
a2ensite default-ssl

Apache 會建立 symlink:

sites-enabled/default-ssl.conf
9. 修改 SSL site 設定

編輯:

/etc/apache2/sites-available/default-ssl.conf

主要設定:

<VirtualHost *:443>

ServerName tile.focusit.tw

SSLEngine on

SSLCertificateFile /opt/ssl_certs/fullchain.pem
SSLCertificateKeyFile /opt/ssl_certs/focusit_tw.key

DocumentRoot /var/www/html

</VirtualHost>
10. HTTP → HTTPS redirect(建議)

編輯:

/etc/apache2/sites-available/000-default.conf

加入:

<VirtualHost *:80>

ServerName tile.focusit.tw

Redirect permanent / https://tile.focusit.tw/

</VirtualHost>
11. Apache config 檢查
apachectl configtest

正常會看到:

Syntax OK
12. 重新載入 Apache
systemctl reload apache2

或

systemctl restart apache2
13. 確認 443 已啟動
ss -lntp | grep 443

應看到:

LISTEN 0 511 0.0.0.0:443
14. SSL 測試

本機:

curl -k https://localhost

或:

openssl s_client -connect tile.focusit.tw:443
15. 消除 Apache ServerName 警告(可選)

編輯:

/etc/apache2/apache2.conf

加入:

ServerName localhost
16. 檔案最終結構
/etc/apache2/ssl/

focusit_tw.key
focusit_tw.crt
gd_bundle.pem
fullchain.pem
17. Apache vhost 結構
/etc/apache2/sites-available/

000-default.conf     (port 80 redirect)
default-ssl.conf     (port 443 SSL)
完成後網站流程
http://tile.focusit.tw
        ↓
301 redirect
        ↓
https://tile.focusit.tw
        ↓
Apache SSL
GIS / MapServer 小提醒

如果是:

Cesium
MapServer
tile server

一定要 HTTPS,否則瀏覽器會:

Mixed Content blocked
最終完成後建議測
https://www.ssllabs.com/ssltest/

可以確認:

certificate chain

TLS version

cipher