【教學】Ubuntu下,建立SSL,讓網站採用https連線

本文可搭配Google Cloud Platform(GCP)架站教學系列文閱讀!
本篇將已取得的SSL憑證,匯入Server端,讓網站採用https連線!


環境 Ubuntu 16.04 LTS

0. 事先準備好SSL憑證,共三個檔案

可參考【教學】透過 SSL For Free 取得 https 免費憑證!
 

啟用SSL mod

sudo a2enmod ssl
※ 務必啟動,不然會出錯誤訊息,無法重啟VM
Job for apache2.service failed because the control process exited with error code. See “systemctl status apache2.service” and “journalctl -xe” for details.
 

上傳 SSL憑證

上傳SSL憑證至VM上  /etc/自建資料夾/
 

更改 .conf

/etc/apache2/sites-available/000-default.conf
※ 此處 conf 係為預設檔,請修改你連結的.conf
 
將 <VirtualHost *:80> 改為 <VirtualHost _default_:443>
並在其下方插入
SSLEngine on
SSLCertificateFile /etc/自建資料夾/certificate.crt
SSLCertificateKeyFile /etc/自建資料夾/private.key
SSLCertificateChainFile /etc/自建資料夾/ca_bundle.crt
 
如果你是由http轉https,請多寫入
<VirtualHost *:80>
ServerName 網域
DocumentRoot /var/www/位置
</VirtualHost>
 
並在.htaccess寫入,強制http轉https
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://網域名%{REQUEST_URI} [L,R]
 

重啟 apache2

sudo service apache2 restart
 
 
完成!
 

相關文章

【淺談】何謂 VPS ,與其功能和特點為何?
【教學】Google Cloud Platform 申請試用,並建立免費專案!
【教學】Google Cloud Platform 下,部署VM環境 Ubuntu16.04 + LAMP
【教學】Google Cloud Platform 下,使用 FileZilla 進行 SSH 連線
【教學】透過 SSL For Free 取得 https 免費憑證!
【教學】Google Cloud Platform 下,安裝WordPress
【解決】WordPress無法更新外掛或外觀佈景!
【教學】將 網域DNS 綁定到 Google Cloud Platform 上
【教學】Google Cloud Platform 設定預算管理,超額立即通知!