Apache2.4.7配置https,解决阿里云证书配置之痛

来源:互联网 发布:刘嘉玲绑架事件知乎 编辑:程序博客网 时间:2024/05/19 06:17

Chrome封杀80网站(http),逼迫小网开启443(https)。如果没有这个的话就会被浏览器或电脑管家认定为不安全的网站,当然可继续访问,但是当很多人投诉你的网站就会立刻想到与木马病毒相关的东西,认为这不是一个好网站。

阿里云服务器开启https还是蛮麻烦的,还好Symantec证书是免费提供1年。虽然阿里云给出了证书及教程,然没有Apache2.4.7版本的。

阿里云提供了3个证书,public.pem和21#######63.key(为SSLCertificateFile),chain.pem(为Server Certificate Chain)。
下面开始配置一下apache2

使用复制密钥,开启ssl

mkdir /etc/apache2/ssl  创建ssl文件夹mv /download/public.pem /etc/apache2/ssl/public.pemmv /download/21#####63.key /etc/apache2/ssl/21#####63.keymv /download/chain.pem /etc/apache2/ssl/chain.pema2enmod ssl  #启用ssl

修改ports.conf

vi /etc/apache2/ports.conf

修改内容为如下

Listen 80<IfModule ssl_module>        Listen 443</IfModule><IfModule mod_gnutls.c>        Listen 443</IfModule>

修改default-ssl

vi /etc/apache2/sites-available/default-ssl

在SSLEngine on 下面找到2行 注释掉

#   SSLCertificateFile directive is needed.     SSLCertificateFile      /etc/apache2/ssl/public.pem     SSLCertificateKeyFile /etc/apache2/ssl/21#####63.key#   Server Certificate Chain:#   Point SSLCertificateChainFile at a file containing the#   concatenation of PEM encoded CA certificates which form the#   certificate chain for the server certificate. Alternatively#   the referenced file can be the same as SSLCertificateFile#   when the CA certificates are directly appended to the server#   certificate for convinience.     SSLCertificateChainFile /etc/apache2/ssl/chain.pem

启用ssl,重启apache

a2ensite default-ssl /etc/init.d/apache2 restart  

htaccess将HTTP访问重定向至HTTPS

RewriteEngine onRewriteBase /RewriteCond %{SERVER_PORT} !^443$RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

重启apache即可使用。

参考资料:
http://blog.csdn.net/newjueqi/article/details/9789659
http://blog.csdn.net/buzaishabi/article/details/39346561

我的博客地址:https://www.nigaea.com/programmer/123.html

0 0
原创粉丝点击