Ubuntu 14 中给 APACHE2安装 SSL 模块
Ubuntu 14 中给 APACHE2安装 SSL 模块
Enable SSL site on Ubuntu 14 LTS, Apache 2.4.7:
参考 http://blog.csdn.net/Sky_qing/article/details/44303221
1. 启用SSL模块
sudo a2enmod ssl
如果不执行这条命令, apache2ctl configtest 检测会有这样的错误
- AH00526: Syntax error on line 43 of /etc/apache2/mods-enabled/ssl.conf:
- SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).
- Action 'configtest' failed.
- The Apache error log may have more information.
2. 给SSL模块作个连接
- ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load
- ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled/ssl.conf
3. 制作数字证书
先生产请求文件 ,也可以在线生成。然后在一些证书颁发网站用这个csr文件 申请证书,比如 comodo
openssl req -new -newkey rsa:2048 -nodes -keyout comodo.key -out comodo.csr
https://www.freehao123.com/comodo-positivessl/
4. 把做好的证书复制到相应目录
- cp server.crt /etc/ssl/certs
- cp server.key /etc/ssl/private
5. 修改配置文件并作个链接
- cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-ssl-default.conf
- ln -s /etc/apache2/sites-available/000-ssl-default.conf /etc/apache2/sites-enabled/001-ssl-default.conf
- vim 001-ssl-default.conf
在<VirtualHost *:80>段中,DocumentRoot一行的下方加入内容:
- SSLEngine On
- SSLOptions +StrictRequire
- SSLCertificateFile /etc/ssl/certs/server.crt
- SSLCertificateKeyFile /etc/ssl/private/server.key
<VirtualHost *:80> 中的80改为443 <VirtualHost *:443>(ssl的端口)
6. 在重启服务前先检查下语法:
apache2ctl configtest
7. 没有错误的话,重启Apache也是很有技巧的:)
- cd /etc/apache2/sites-enabled
- a2enmod ssl
- a2ensite 001-ssl-default
- service apache2 reload
- service apache2 restart
如果更改了 APACHE2 的模块,在重启服务器之前,这个 service apache2 reload 指令或不可少,对 添加了 SSL 模块而言,缺少这条指令,HTTPS:// 会有如下错误
- chrome浏览器: ERR_SSL_PROTOCOL_ERROR
- firefox浏览器: SSL 接收到一个超出最大准许长度的记录。 错误代码: SSL_ERROR_RX_RECORD_TOO_LONG
- IE 浏览器: 确保启用了 TLS 和 SSL 协议。转到“工具”>“Internet 选项”>“高级”>“设置”>“安全”
- Openssl/ Wget : error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
无法找到php包时
$ apt install -y software-properties-common
$ add-apt-repository ppa:ondrej/php
$ sudo apt-get update //更新包管理