1、服务器开启HTTPS支持
安装openssl
sudo apt-get install openssl
开启Apache的ssl支持
sudo a2enmod ssl
打开监听443端口:/etc/apache2/ports.conf
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
站点开启SSL服务,指定证书文件:/etc/apache2/sites-enabled/yourdomain.conf
<VirtualHost yourdomain:443>
ServerName yourdomain
ServerAdmin xxx@domain.com
DocumentRoot /var/www/dir
#开启服务
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
#指定证书文件
SSLCertificateFile /etc/apache2/ssl/yourdomain/fullchain.pem
SSLCertificateKeyFile /etc/apache2/ssl/yourdomain/privkey.pem
</VirtualHost>
2、申请CA证书
Google和Mozilla宣布将在2018年不再信任Symantec所颁发的CA证书,原来在阿里云申请的一年免费Symantec证书不再使用,改为Let’s Encrypt颁发的3个月的免费证书。
Let’s Encrypt官方推荐的命令行证书获取方法是通过Certbot工具来自动获得:
Certbot安装:
$ sudo apt-get update |
开始
如果需要Certbot自动配置apache:
sudo certbot --apache
如果只需要申请CA证书:
sudo certbot --apache certonly
自动续签
$ sudo certbot renew --dry-run |
我的证书在哪呢?
所有私匙文件和证书文件都可以在/etc/letsencrypt/live/$domaim
文件夹内找到。请将你的服务器设置直接指向这些文件,或者为其创建符号链接,而不是将其拷贝过来使用。这样在续签证书的时候可以直接升级到最近的版本。
privkey.pem
证书的私匙文件
fullchain.pem
证书文件。所有的证书内容都在这个文件内,包括服务器证书。
Apache2>=2.4.8版本时,SSLCertificateFile需要fullchain.pem。
cert.pem
and chain.pem
Apache<2.4.8版本时,SSLCertificateFile需要cert.pem,SSLCertificateChainFile需要chain.pem。
3、 创建自己的私匙和csr文件
首先安装openssl
openssl req -newkey rsa:2048 -keyout yourname.key -out yourname.csr