lighttpd部署ssl证书指南
作者:龚辉
来源:《经营管理者·上旬刊》2017年第11
        随着网络安全形势的变化,以及AppleGoogle大力推广https协议,https协议将成为今后网站的主流。https,全称Hyper Text Transfer Protocol Secure,由http发展而来。http协议运行在TCP之上,所有传输的内容都是明文,客户端和服务器端都无法验证对方的身份。httpshttp运行在tls/ssl之上,tls/ssl运行在TCP之上。所有传输的内容都经过加密,加密采用对称加密,但对称加密的密钥用服务器方的证书进行了非对称加密。此外客户端可以验证服务器端的身份,如果配置了客户端验证,服务器方也可以验证客户端的身份。所以https协议保证了比http协议更高的安全性。
        下面简述 lighttpd 部署 ssl 证书的步骤(服务器系统环境:ubuntu 16.04 x86,客户端:win7):
        1.服务器系统更新。
        #su root
        #sudo apt upgrade
        2.服务器安装 lighttpd
        #sudo apt-get -y install lighttpd
        在客户端浏览器输入服务器IP地址,检查能否看到lighttpd默认主页,以验证lighttpd安装。另外说明一下lighttpd的相关信息:
        Lighttpd 默认根目录: /var/www/html
        配置文件:/etc/f
        其他配置文件:/etc/lighttpd/conf-available
        查看 lighttpd 是否支持ssl 版本信息中含有(ssl)字样就说明支持ssl
        # /usr/sbin/lighttpd -v
        lighttpd/1.4.35 ssl - a light and fast webserver
        Build-Date Apr 18 2016 153658
        3.服务器确保正确安装了openssl
        安装 openssl
        #sudo apt-get install openssl
        查看 openssl 版本
        # openssl version -a
        4.修改lighttpd配置文件 /etc/f
        加入或修改一下内容:
        $SERVER["socket"] == "443" {
        ine = "enable"
        server.document-root = "/var/www/html"
        log = "/usr/log/lighttpd/error.log"
        ssl.pemfile = "/etc/lighttpd/mytnln.pem"
        ssl.ca-file = "/etc/"
        }
        #强制定向到 HTTPS
        #下面是 f 文件中关于强制 HTTP 定向到 HTTPS 的部分配置
        $HTTP["scheme"] == "http" {
        $HTTP["host"] = ".*" {
        direct = ".*" => "https//%0$0"
        }
        }
        #Lighttpd 安全配置
        #禁用 SSLv2 SSLv3
        ssl.use-sslv2 = "disable"
        ssl.use-sslv3 = "disable"
        5.证书准备。
        lighttpd所需pem文件包含密钥(KEY)及域名证书(CRT/CER)。密钥文件由自己产生,域名证书需要到证书发行机构申请。这里采用startcomhttps//www.startcomca/ 发行的免费证书。
        制作密钥文件及证书签名请求文件:
        首先 生成 证书签名请求文件 mytnln.csr,命令如下:
        openssl req -newkey rsa2048 -keyout mytnln.key -out mytnln.csr
        在这一命令执行的过程中,会要求填写如下信息:
        Country Name 2 letter code):使用国际标准组织(ISO)国码格式,填写2个字母的国家代号。中国请填写CN
        State or Province Name full name):省份,比如填写Shanghai
        Locality Name eg city):城市,比如填写Shanghai
        Organization Name eg company):组织单位,比如填写公司名称的拼音
        Organizational Unit Name eg section):比如填写IT Dept
        Common Name eg your websites domain name):行使 SSL 加密的网站地址。
        请注意这里并不是单指您的域名,而是直接使用 SSL 的网站名称,例如:m.xxx。一个网站这里定义是:xxx 是一个网站; 也是一个网站;m.xxx 又是另外一個网站。
        Email Address:邮件地址,可以不填
        A challenge password:可以不填
        An optional company name:可以不填
        根据要求 生成 mytnln.key mytnln.csr,提交 csr 文件 startcom 网站(https//www.startcomca/ 申请 免费 ssl 证书文件,下载 下来 的证书文件压缩包中 适用于 各个 http server 证书文件。
        合成PEM文件:
        取用证书文件压缩包 OtherServer 目录中的文件(2_),
        cat mytnln.key 2_ > mytnln.pem
        生成中间证书。
        为了确保兼容到所有浏览器,我们必须部署中间证书,如果不这么做,虽然部署过程并不会报错,但可能导致免费ssl证书永久生成Android系统,Chrome Firefox等浏览器无法识别。
        请到 中间证书下载工具(https//ssl/tools/downloadchain.html),粘贴输入1_ntsc.,下一步,然后下载中间证书
        为安全计,对中间证书及pem 文件 设置权限:
        chmod 400 mytnln.pem (仅root可读)
        chmod (仅root可读)
        如果这样配置还无法正常显示网站,需要将startcom 根证书手工导入到浏览器中(firefoxchromeIE),并添加信任。
        startcom 根证书下载:
        https//www.startcomca/ 登录,tool box -- StartCom CA Certificates -- Root CA Certificates,下载 Root 1 - StartCom Certification Authority G3 根證书,文件名:StartComCertificationAuthorityG3.cacert.pem
        6.重新加载Lighttpd
        service lighttpd force-reload
        7.验证ssl证书安装。
        在客户端打开 firefox 浏览器,访问部署的http// 网站,验证是否 跳转到 https//,查看是否显示 绿锁状态,查看证书信息。
        8.ssl安装检测。
        最后到 https//www.ssllabs/ssltest/ https//myssl/ 进行SSL安装检测。