如何在Lighttpd服务器中配置SSL

时间:2019-05-19 01:25:45  来源:igfitidea点击:

所有使用SSL运行的站点在默认端口443上使用https协议。
SSL通过加密服务器和客户机之间的数据来提供安全的数据通信。

本文将在Lighttpd服务器中配置SSL。
在本例中,我们使用自签名证书。

步骤1:创建证书签名请求(CSR)

要创建SSL证书,第一个要求是创建私钥和CSR。
CSR是一个文件,它包含域的所有细节,包括一个公钥。
首先创建一个目录,在其中创建csr和密钥。

# mkdir /etc/lighttpd/ssl/
# cd /etc/lighttpd/ssl/

现在用下面的命令创建CSR和密钥文件。
根据域名更改文件名称 example.com.keyexample.com.csr
此命令将要求输入有关域的信息。

# openssl req -new -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr

Generating a 2048 bit RSA private key
....+++
...............+++
writing new private key to 'example.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:Delhi
Locality Name (eg, city) [Default City]:Delhi
Organization Name (eg, company) [Default Company Ltd]:theitroad Inc.
Organizational Unit Name (eg, section) []:web
Common Name (eg, your name or your server's hostname) []:example.com
Email Address []:Hyman@theitroad

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: [留空]
An optional company name []: [留空]

步骤2:从CA请求证书

创建CSR后,向任何证书提供商(如Geotrust、Comodo、Digicert或GoDaddy等)请求SSL证书。
或者创造一个内部使用。
我们不建议生产站点使用这种方法。

# openssl x509 -req -days 365 -in example.com.csr -signkey example.com.key -out example.com.crt

我们将在当前目录中创建名为 example.com.crt的证书文件。
现在通过在一个文件中组合密钥文件和证书来创建pem文件

# cat example.com.key  example.com.crt > example.com.pem

步骤3:用SSL设置虚拟主机

编辑Lighttpd配置文件 /etc/lighttpd/lighttpd.conf
并添加以下值。

$SERVER["socket"] == ":443" {
        ssl.engine = "enable"
        ssl.pemfile = "/etc/lighttpd/ssl/theitroad.com.pem"
      # ssl.ca-file = "/etc/lighttpd/ssl/CA_issuing.crt"
        server.name = "site1.theitroad.com"
        server.document-root = "/sites/vhosts/site1.theitroad.com/public"
        server.errorlog = "/var/log/lighttpd/site1.theitroad.com.error.log"
        accesslog.filename = "/var/log/lighttpd/site1.theitroad.com.access.log"
}

步骤4:验证配置并重启Lighttpd

在启动lighttpd服务之前,验证配置文件的语法。

# lighttpd -t -f /etc/lighttpd/lighttpd.conf

Syntax OK

如果我们发现所有语法都是正确的,那么让我们重新启动service

# service lighttpd restart