Howto: Linux Lighttpd SSL (secure server layer) https 安装和配置
SSL是一种加密协议,为电子邮件、web网页等Internet服务提供安全的通信。
SSL证书是一种数字证书,用来标识网站并且使用SSL技术加密服务器和客户端通信时的数据。
SSL对电子商务网站特别有用,使用网上银行付款、用户登录和注册等行为都离不开SSL。
为了要购买一个数字证书,你必须先生成一个Certificate Signing Request (CSR),并提交给Certification Authority (CA)。CSR中包含有你使用证书的程序的相关信息,还有你的public key。你的Web服务器软件可以生成CSR(openssl命令),同时生成public/private key,这将用来加密和解密你的安全链接。
必备条件
- Lighttpd webserver with SSL support
- 独立IP地址
- CA颁发给你的SSL 证书
- 域名 – theos.in (为方便举例,这里使用 theos.in )
服务器上一些重要文件
- /etc/lighttpd/theos.in/ – 存储SSL证书和相关文件的目录
- /etc/lighttpd/theos.in/theos.in.key – 你的private key,永远不要把这个文件给别人,lighttpd用这个文件来加密信息。
- /etc/lighttpd/theos.in/theos.in.csr – 当你去CA处请求颁发SSL证书时,你需要将这个文件的内容提供给他们,这里面有你的public key。
- /etc/lighttpd/theos.in/theos.in.pem – 这个文件里面包含了private keys (RSA and DSA), public keys (RSA and DSA) 和 (x509) 证书通常,你的密钥和证书都存放在这个文件中。
CA的一些重要文件
- CA_issuing.crt – 你的 intermediate certificate 或 chained root certificate 文件。
- theos.in.crt – 你的域名证书。
以下是具体步骤
Step # 1: 生成certificate signing request (CSR)
首先,用openssl命令生成域名theos.in的certificate-signing request:
# mkdir -p /etc/lighttpd/ssl/theos.in
# cd /etc/lighttpd/ssl/theos.in
创建 RSA key:
# openssl genrsa -des3 -out theos.in.key 1024
创建CSR:
# openssl req -new -key theos.in.key -out theos.in.csr
程序会提示你输入域名等信息。如果你申请通配证书(wildcard certificate),请用*号,比如*.theos.in。这样,你的子域名也可以用这个证书。
然后,把theos.in.csr提交到CA,通常,这是CA要让你交钱,还要验证你是这个域名的所有者。一旦CA批准了你的申请,你就可以下载证书并将其用在lighttpd服务器上了。
Step # 2: 准备证书
你的CA已经颁发给你证书,你要做的就是将这个证书安装在lighttpd服务器上。
复制下载下来的证书 (theos.in.crt) 到 /etc/lighttpd/ssl/theos.in
# cp theos.in.crt /etc/lighttpd/ssl/theos.in
生成 pem 文件、设置权限:
# cat theos.in.key theos.in.crt > theos.in.pem
# chmod 0600 theos.in.pem
# chown lighttpd:lighttpd /etc/lighttpd/ssl/theos.in -R
Step #3: 确保lighttpd支持ssl
用以下命令检查lighttpd是否支持ssl:
[vivek@cyberciti.biz]$ /usr/sbin/lighttpd -v
lighttpd-1.4.11 (ssl) – a light and fast webserver
Build-Date: Jul 12 2006 13:47:40
否则,参考安装和配置lighttpd。
Step #4: 配置lighttpd,是你的域名支持ssl
打开lighttpd配置文件
# vi /etc/lighttpd/lighttpd.conf
加下面这段信息:
$SERVER["socket"] == "theos.in:443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/theos.in/theos.in.pem"
ssl.ca-file = "/etc/lighttpd/theos.in/CA_issuing.crt"
server.name = "theos.in"
server.document-root = "/home/lighttpd/theos.in/https"
server.errorlog = "/var/log/lighttpd/theos.in/serror.log"
accesslog.filename = "/var/log/lighttpd/theos.in/saccess.log"
}
其中,
- ssl.engine = "enable" : 打开lighttpd ssl开关
- ssl.pemfile = "/etc/lighttpd/theos.in/theos.in.pem" – 你的PEM文件
- ssl.ca-file = "/etc/lighttpd/theos.in/CA_issuing.crt" – 你的 intermediate certificate 文件
保存并关闭这个文件。重启lighttpd服务器(会提示你输入SSL private key的密码):
# /etc/init.d/lighttpd restart
显示:
Password:
打开浏览器输入url: https://yourdomain.com (https://theos.in),测试ssl是否工作正常。
翻译自:http://www.cyberciti.biz/tips/how-to-install-ssl-lighttpd-https-configuration.html
注:一般CA的证书都需要钱,如果需要免费的,可使用self-signed证书,或者去http://www.cacert.org
Recent Comments