為了使系統支持https模式,首先我們要使能ssl模式。
命令如下:
sudo a2enmod ssl
sudo systemctl restart apache2
接下來我們要生成一個SSL/TLS 認證,下面的命令就是產生一個TLS命令並且生成一個私鑰:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/example.com.key -out /etc/ssl/certs/example.com.crt
應用SSL簽名:
創建一個虛擬的Host 文件,在目錄下 /etc/apache2/site-available 的(e.g. example.com-ssl.conf) 具體配置信息:
<VirtualHost *:443> ServerName www.example.com ServerAlias example.com DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/ssl/certs/example.com.crt SSLCertificateKeyFile /etc/ssl/private/example.com.key </VirtualHost>
最后,使能https並且重啟Apache服務。
sudo a2ensite example.com-ssl.conf
sudo systemctl reload apache2
參考文檔:
1 https://www.configserverfirewall.com/hosting/openssl-ubuntu-self-signed-certificate/