https-ssl-nginx-apache-httpd-tomat申请ssl证书小结

更新:因ios10不支持startSSL的免费证书,看这里:https://support.apple.com/zh-cn/HT204132

StartSSL 是 StartCom 公司旗下的 SSL 证书

ios9都没问题,ios10就不支持了,所以不要用startSSL啦

关于免费证书选择,看这里:http://www.cocoachina.com/bbs/read.php?tid-1708524.html

不过七牛证书不可下载,放弃

后来申请阿里云的免费证书,ios10认证通过,就用阿里云的免费证书了

注意:

1.验证域名选择dns,域名控制哪里要选择txt类型

2.生成csr的时候选择系统自动生成,可以省去很多麻烦

阿里云生成的证书适配各种代理服务器或容器,如nginx,apache,tomcat,iis等,非常方便


首次申请ssl证书,本次配置的环境是 CentOS release 6.6,apache httpd-2.4.10,注意不要看windows keytool那一套资料了

本次申请的是免费的ssl证书, 一般在Let's Encrypt和startSSL中选一个

Let's Encrypt是执行/certbot-auto命令,需要python 2.7以上环境,弄了一阵没搞定,放弃,改为startSSL

startSSL已经改版了,所以要搜索改版后的startSSL说明网页,不要管老版本的那一套网页

也有人推荐使用阿里云的赛门铁克 SSL/TLS 证书,是微信支持的,可以免费申请使用一年,没试过。


首先弄清楚是配置apache httpd还是tomcat,参考 http://unmi.cc/apache-ssl-tomcat/


httpd配置:

httpd开启ssl后start failed,查看日志 /etc/httpd/logs/ssl_error_log

 conf 目录中的 httpd.conf 文件,找到以下内容并去掉“#”:

#LoadModule ssl_module modules/mod_ssl.so (如果找不到请确认是否编译过 openssl 插件)
#Include conf/extra/httpd-ssl.conf
httpd-ssl.conf配置server.key和server.crt

  • 创建并切换到ssl目录

  1. mkdir -p /etc/httpd/ssl
  2. chmod 600 /etc/httpd/ssl
  3. cd /etc/httpd/ssl
  • 生成证书和密钥

  1. # 建立服务器密钥
  2. openssl genrsa -out server.key 1024
  3. # 建立服务器公钥
  4. openssl req -new -key server.key -out server.csr
  5. # 建立服务器证书
  6. openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt


以下流程是startSSL的,已作废

1.

首先centos执行命令 openssl req -newkey rsa:2048 -keyout yourname.key -out yourname.csr

一些字段可参考:http://blog.csdn.net/fyang2007/article/details/6180361

生成key和csr文件

2.

用第1步生成的csr在startSSL网站上生成认证后的证书并下载

参考 

http://www.devsai.com/2016/11/21/tech-https-30min/

https://www.freehao123.com/startssl-ssl-apache-ngnix/

3.

如果是nginx的很简单,上面的连接http://www.devsai.com/2016/11/21/tech-https-30min/有说明

如果是apache的话也很简单,把ApacheServer里面的两个crt文件上传到服务器

4.

配置httpd,参考 http://unmi.cc/apache-ssl-tomcat/

虚拟主机配置,第1步生成的key文件和第3步生成的两个crt文件配置进去,供参考:


    ServerName www.abc.com

   
        Order deny,allow
        Allow from all
   



    SSLProxyEngine on
    SSLProxyVerify none 
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off 
    SSLCertificateFile /etc/pki/tls/certs/example.com.crt
    SSLCertificateKeyFile /etc/pki/tls/private/example.key
    SSLCertificateChainFile /etc/pki/tls/certs/example_root_bundle.crt
    SSLProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2

    ProxyPass / ajp://localhost:8011/
    ProxyPassReverse / ajp://localhost:8011/

    ErrorLog "/home/logs/httpd/17t1t-ssl-error.log"
    CustomLog "/home/logs/httpd/17t1t-ssl.log" common


最后443端口记得打开,服务器和路由器都要

查看ssl是否配置正确,访问这个网站输入域名即可看到结果: https://www.ssllabs.com/ssltest/analyze.html

最后访问自己的域名,就可以啦


--------------------------------------分隔线-----------------------------------------------


以下是遇到的问题小结:


python 2.6版本比较老,想升级

yum remove python
Error: Trying to remove "yum", which is protected

虽然可以通过rpm -e --nodeps yum来移除,不过yum就用不了了

所以可用这个链接的方法安装  https://teddysun.com/473.html


报错:

Proxy Error
The proxy server could not handle the request GET /web_app.
Reason: Error during SSL Handshake with remote server

解决办法,配置中加上几个选项:
In the case of Apache 2.4 and up, there are different defaults and a new directive.
I am running Apache 2.4.6, and I had to add the following directives to get it working:
SSLProxyEngine on
SSLProxyVerify none 
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off


报错:

SSLSessionCache: 'shmcb' session cache not supported (known names: ). 
Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

解决办法,放开注释:

apache/conf/httpd.conf 
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so


报错:

SSL Library Error: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch

解决办法,可以先校验key和crt的是否一致:
openssl x509 -noout -modulus -in 2_www.17t1t.com.crt | openssl md5
openssl rsa -noout -modulus -in 17t1t.key | openssl md5


你可能感兴趣的:(后端)