申请通过颁发证书后,去下载证书:*.crt、*.key、root_*.crt
sudo apt-get install openssl
输入 sudo a2enmod ssl
无效则输入下面两个命令
sudo ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load sudo ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled/ssl.conf
复制
mkdir /etc/apache2/cert
进入/etc/apache2/ports.conf, 查看是否有
Listen 80 Listen 443
没有就添加上去
sudo vim /etc/apache2/sites-enabled/000-default.conf
添加
<VirtualHost *:443> SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM SSLHonorCipherOrder on SSLCertificateFile cert/xxx_public.crt SSLCertificateKeyFile cert/xxx.key SSLCertificateChainFile cert/xxx_chain.crt ServerAdmin webmaster@localhost DocumentRoot 项目地址 ServerName www.xxx.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>
复制
打开 /etc/apache2/sites-available/000-default.conf , 在 <\VirtualHost *:80><\VirtualHost> 标签内随便一个地方加入以下三行
RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R=301]
复制
sudo service apache2 restart