https简介

    http协议在网络中是以明文传输的,自然安全性不高。https使用了ssl加密机制,弥补了这点不足。
    http:80端口
    https:443端口

案例:

    自建CA,实现一个https安全的会话机制。
    这里为了方便期间,CA和web服务器是用一台服务器共同实现
  1. web生成并提交请求

    [root@web CA]# (umask 077;openssl genrsa 1024 > httpd.key)
    [root@web CA]# openssl req -new -key httpd.key -out httpd.csr


  2. 自建ca

    [root@web CA]# (umask 077;openssl genrsa 2048 > private/cakey.pem)
    [root@web CA]# openssl req -new -x509 -key private/cakey.pem -days 365 -out cacert.pem


  3. web服务器端发给CA签署(可以使用scp命令)
     

    [root@web ssl]# openssl ca -in httpd.csr -out httpd.crt


  4. 签署成功后有CA服务器发送个web,此时web服务器端就得到了3个相关私钥和证书

    [root@web ssl]# pwd
         /etc/httpd/conf/ssl
     [root@web ssl]# ls
     httpd.crt  httpd.csr  httpd.key


  5. 接下来开始部署我们web支持ssl功能了,想要支持ssl,apache必须加载mod-ssl模块

  6. 查看我们的apache是否已经配置支持了ssl

    [root@web ~]# grep mod_ssl /etc/httpd/conf/httpd.conf
    # (e.g. :80) if mod_ssl is being used, due to the nature of the
    [root@web ~]# grep mod_ssl /etc/httpd/conf.d/*.conf


  7. 既然grep不到,说明没有支持,此时我们需要安装一个mod_ssl

    [root@web ~]# yum -y install mod_ssl
    [root@web ~]# rpm -ql mod_ssl
    /etc/httpd/conf.d/ssl.conf
    /usr/lib64/httpd/modules/mod_ssl.so
    /var/cache/mod_ssl
    /var/cache/mod_ssl/scache.dir
    /var/cache/mod_ssl/scache.pag
    /var/cache/mod_ssl/scache.sem


  8. 查看一下新安装的配置文件吧,这里加载了ssl的模块支持,和新的端口号443等。

    [root@web ~]# vim /etc/httpd/conf.d/ssl.conf
    LoadModule ssl_module modules/mod_ssl.so
    Listen 443
    <VirtualHost _default_:443>


  9. 我们需要修改一下这个配置文件,让其知道我们的web服务器的证书在哪里,私钥在哪里,以方便把我们的证书发给客户端,并且用私钥解密客户端用我们的证书中的公钥加密的对称密码。

    <VirtualHost _default_:443>
    # General setup for the virtual host, inherited from global configuration
    DocumentRoot "/var/www/html"
    ServerName www.magelinux.com:443--------要与证书申请时对应
    ErrorLog logs/ssl_error_log-------------日志文件
    TransferLog logs/ssl_access_log
    LogLevel warn---------------------------日志级别
        SSLEngine on----------------------------是否开启ssl功能
        #   SSL Protocol support:
        # List the enable protocol levels with which clients will be able to
        # connect.  Disable SSLv2 access by default:
        SSLProtocol all -SSLv2
        #   SSL Cipher Suite:
        # List the ciphers that the client is permitted to negotiate.
        # See the mod_ssl documentation for a complete list.
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
        #   Server Certificate:
        SSLCertificateFile /etc/httpd/conf/ssl/httpd.crt------证书位置
        #   Server Private Key:
        SSLCertificateKeyFile /etc/httpd/conf/ssl/httpd.key---私钥位置


  10. 通过命令ss -tunl 可以看出此时443端口已经开始监听了,此时通过浏览器访问会提示证书不守信用,有风险,这是因为我们的证书是我们自建的CA签署的,客户端没有认可

    自建的CA配置基于mod_ssl模块实现对ssl的支持_mod_ssl XIU

  11. 将CA证书导入到我们的客户端电脑,并安装。

    自建的CA配置基于mod_ssl模块实现对ssl的支持_mod_ssl _02自建的CA配置基于mod_ssl模块实现对ssl的支持_https _03

    自建的CA配置基于mod_ssl模块实现对ssl的支持_https _04

  12. 当然我们也可以用openssl s_client -connect ip:443来诊断(man s_client)