您的位置:首页 > 理论基础 > 计算机网络

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

2017-01-05 00:00 603 查看
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.pem
mv /download/21#####63.key /etc/apache2/ssl/21#####63.key
mv /download/chain.pem /etc/apache2/ssl/chain.pem
a2enmod 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.conf

在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 on
RewriteBase /
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apache 阿里云