免费证书

LAMP

https(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的 http 通道,简单讲是 http 的安全版。即 http 下加入 SSL 层,https 的安全基础是 SSL,因此加密的详细内容就需要 SSL。

LAMP 目前使用 acme.sh 来签发 Letsencrypt.orgBuypass.com 免费的证书,并添加自动任务到 crond,定期运行自动更新证书。当然也可以指定自定义证书。

安装完 LAMP 后,lamp 命令就可以使用了,用法如下。

Usage  : lamp [Options]
Options:
        add      Create a new Apache virtual host
        del      Delete a Apache virtual host
        list     List all of Apache virtual hosts
        version  Print version and exit

下面为使用 lamp 命令增加 SSL 证书支持的详细使用教程。

新增虚拟主机
注意:在新增虚拟主机之前,请务必确保域名已经解析到该服务器或 VPS 的 IP 上,否则在发行免费证书时,域名验证无法通过。

使用命令:

lamp add

交互显示如下:

Please enter server names (for example: lamp.sh www.lamp.sh): 此处输入域名(一个或多个)
Please enter website root directory (default: /data/www/域名): 此处输入网站根目录路径,如果留空则为默认路径
Website root directory: 此处显示上一步输入的网站根目录路径
Please enter Administrator Email address: 此处输入管理员邮箱地址
Administrator Email address: 此处显示上一步输入的邮箱地址
Do you want to create a database and user with same name? [y/n]: 此处输入 y 或 n,表示创建或不创建数据库
Created virtual host [域名] success
Website root directory is: 此处显示网站根目录路径
Reloading the Apache config file...
Reload success
Do you want to add a SSL certificate? [y/n]: 此处输入 y 或 n,表示添加或不添加证书
1. Use your own SSL Certificate and Key
2. Use Let's Encrypt CA to create SSL Certificate and Key
3. Use Buypass.com CA to create SSL Certificate and Key
Please enter 1 or 2 or 3: 此处输入 1,2 或 3。1 表示使用自己的证书;2 使用 Let's Encrypt 签发免费证书;3 使用 Buypass.com 签发免费证书。
Do you want force redirection from HTTP to HTTPS? [y/n]: 此处输入 y 或 n,询问是否强制 http 转 https
Added SSL certificate for virtual host [域名] success
Reloading the Apache config file...
Reload success
All done

结束后,查看 crond 任务,命令如下:

crontab -l

确认返回值里包含以下 2 条 acme.sh 即可:

7 0 * * * "/usr/local/acme.sh"/acme.sh --cron --home "/usr/local/acme.sh" > /dev/null
0 3 */7 * * /usr/local/acme.sh/upgrade.sh

签发的证书和私钥路径:

/usr/local/apache/conf/ssl/域名/fullchain.cer
/usr/local/apache/conf/ssl/域名/域名.key

创建完虚拟主机后,网站的根目录为:/data/www/域名
日志文件的目录为:/data/wwwlog/域名

最后,别忘了将你的程序放到网站根目录下,即可使用。
祝使用愉快!

评论已关闭