让Apache支持SSL

By | 2018-11-27
先建立憑證檔案
sudo mkdir /etc/apache2/ssl
sudo openssl req -new -x509 -nodes -out /etc/apache2/ssl/apache.crt -keyout /etc/apache2/ssl/apache.key

啟動 Apache 的 ssl 模組
sudo a2enmod ssl

加入監聽port
sudo nano /etc/apache2/ports.conf
加一行
Listen 443

加入虛擬伺服器

sudo nano /etc/apache2/sites-available/default
原來的
NameVirtualHost *
<virtualhost *>
     ..........
     .......
     ....
</virtualhost>

改成
NameVirtualHost *:80
<virtualhost *:80>
     ..........
     .......
     ....
</virtualhost>

最下面新增
NameVirtualHost *:443
<virtualhost *:443>
   # 預設網頁根目錄 /var/www/https/  可按照需求更改, 相關權限再另外參考 Apache 設定
   DocumentRoot /var/www/https/
  ErrorLog /var/log/apache2/error.log
  CustomLog /var/log/apache2/access.log combined
  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/apache.crt
  SSLCertificateKeyFile /etc/apache2/ssl/apache.key
</virtualhost>

發佈回覆