LAMP新增Letsencrypt支持

技术 秋水逸冰 47368浏览 33评论

https(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的 http 通道,简单讲是 http 的安全版。即 http 下加入 SSL 层,https 的安全基础是 SSL,因此加密的详细内容就需要 SSL。
LAMP 新增对 Let’s Encrypt 的支持,自动签发免费的证书,并添加自动任务到 crond,定期运行自动更新证书。
安装完 LAMP 后,lamp 命令就可以使用了,用法如下。

Usage: lamp [ add | del | list ]
add     Create new Apache Virtual Host
del     Delete Apache Virtual Host
list    List all of Apache Virtual Host

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

新增虚拟主机

注意:在新增虚拟主机之前,请务必确保域名已经解析到该服务器(VPS)的 IP 上,否则 Let’s Encrypt 验证无法通过。
使用命令:

lamp add

交互显示如下:

Please enter server names(example: www.lamp.sh lamp.sh): 此处输入网站域名
Please enter website root directory(default:/data/www/网站域名): 此处输入网站根目录路径,默认回车即可
Please enter Administrator Email address: 此处输入管理员邮箱地址
Administrator Email address: 此处显示上一步输入的邮箱地址
Do you want to create a database and mysql user with same name? [y/n]: 此处输入 y 或 n,表示创建或不创建数据库(输入 y)
Virtual host [网站域名] has been created
Website root directory is: /data/www/网站域名
Database [数据库名] and mysql user [数据库用户名] has been created // 数据库及同名用户创建成功
Reloading the apache config file...
Syntax OK
Reload success
Do you want to add a SSL certificate? [y/n]: 此处输入 y 或 n,表示添加或不添加证书(输入 y)
1: Use your own SSL Certificate and Key
2: Use Let's Encrypt to create SSL Certificate and Key
Please enter 1 or 2: 此处输入 1 或 2,表示使用自己的证书,或使用 Let's Encrypt 签发免费证书(输入 2)
You have already chosen Let's Encrypt
It will be processed automatically
Installing certbot command...
此处开始下载安装 certbot 命令
Starting create Let's Encrypt SSL Certificate...
此处开始安装 certbot 运行所需的依赖库等
Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for 网站域名
Using the webroot path /data/www/网站域名 for all unmatched domains.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/网站域名/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/网站域名/privkey.pem
   Your cert will expire on 2018-02-02. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Let's encrypt crontab renew rule is not exist, create it!
Create Let's Encrypt SSL Certificate successfully
Reloading the apache config file...
Syntax OK
Reload success
All done

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

crontab -l

确认返回值里包含以下语句:

0 3 */7 * * /bin/certbot renew --disable-hook-validation --renew-hook "/etc/init.d/httpd restart"

Let’s Encrypt 签发的证书和私钥路径:

/etc/letsencrypt/live/网站域名/fullchain.pem
/etc/letsencrypt/live/网站域名/privkey.pem

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

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

转载请注明:秋水逸冰 » LAMP新增Letsencrypt支持

发表我的评论
取消评论

请输入正确答案后提交评论 *超出时限。 请再次填写验证码。

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (33)

  1. 博主,安装时下载包的速度很慢,能不能再百度云上传个完整包?
    不知天命6年前(2018-03-14)回复
  2. 你好Teddy,有一个问题请教:lamp add 成功后浏览器显示的总是/data/www/default的内容,如何显示/data/www/my-domain的内容? 谢谢!
    jazzi6年前(2018-03-08)回复
  3. 博主,lamp和lnmp哪个在国外vps上面搭建wordpress运行速度快?
    鸟叔の窝6年前(2018-01-25)回复
  4. Installing Python packages... Traceback (most recent call last): File "/tmp/tmp.oRZkn8EPzI/pipstrap.py", line 165, in exit(main()) File "/tmp/tmp.oRZkn8EPzI/pipstrap.py", line 146, in main for url, digest in PACKAGES] File "/tmp/tmp.oRZkn8EPzI/pipstrap.py", line 121, in hashed_download response = opener().open(url) File "/usr/lib64/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "/usr/lib64/python2.7/urllib2.py", line 449, in _open '_open', req) File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "/usr/lib64/python2.7/urllib2.py", line 1240, in https_open context=self._context) File "/usr/lib64/python2.7/urllib2.py", line 1197, in do_open raise URLError(err) urllib2.URLError: Error: Create Let's Encrypt SSL Certificate failed! Reloading the apache config file... Syntax OK Reload success All done 秋大,这个报错不会解决了, ssl报错,站点只有http可以访问
    MMi6年前(2018-01-04)回复
    • 系统是Debian 8.0 64,使用最新的脚本安装的
      MMi6年前(2018-01-04)回复
    • 这就是代表创建 Letsencrypt 的 SSL 证书遇到 urllib2.URLError 错误了。 这种错误提示可能会有很多种原因造成,建议你去搜索看看,尝试先解决这个问题,然后重新运行 lamp add 再试试。
      秋水逸冰6年前(2018-01-05)回复
    • urllib2.URLError: 请问下你们的这个问题解决了吗,python中加了这句ssl._create_default_https_context = ssl._create_unverified_context,重新lamp add,还是报错 -_-
      North_Mars6年前(2018-01-14)回复
  5. 请问一下秋大,这么重启php
    longyujin96年前(2017-12-29)回复
  6. 呃呃呃,支持支持还是支持~ 口头上的那啥 感谢提供客户端图片导入配置功能! 高上大啊~~~ 虽然我只能自己用用~~
    r26年前(2017-11-24)回复
  7. 我重装了lamp执行lamp add还是原来的,并没有ssl配置的选项,需要有什么操作吗?
    L6年前(2017-11-18)回复
    • 请使用最新的脚本来安装。
      秋水逸冰6年前(2017-11-18)回复
      • 可以了秋大,我以为他会覆盖掉,结果不会,后来把/root/lamp删掉在安装就可以了,新的安装过程中有报错
        L6年前(2017-11-18)回复
      • 可以了秋大,我以为他会覆盖掉,结果不会,后来把/root/lamp删掉在安装就可以了,新的安装过程中有报错 error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.后来装了 libc-client-devel 就可以了,系统是centos7
        L6年前(2017-11-18)回复
  8. Ubuntu 16.04 LTS下一直出现这个错误: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in main() File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main symlink=options.symlink) File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment download=download, File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT) File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess % (cmd_desc, proc.returncode)) OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 2 Error: Create Let's Encrypt SSL Certificate failed! 重装了virtualenv等之后还是没用。大佬可否解决一下?谢谢!
    root6年前(2017-11-16)回复
    • 这是 certbot 在你的环境里没法正确安装依赖包导致的错误。 好像是因为 pip 安装某些包时下载失败造成的。
      秋水逸冰6年前(2017-11-16)回复
  9. 大师,之前提供toad下载的页面不见了,能否提供一个呢?
    tomorrower6年前(2017-11-14)回复
    • 涉及到 DMCA 被要求删除了。抱歉。
      秋水逸冰6年前(2017-11-14)回复
      • 大师,能否发给我一份12.12的?tomorrower#tom.com
        tomorrower6年前(2017-11-16)回复
  10. 大佬,想问下你这个 流量的插件 是哪个?有名字吗 谢谢
    MasTT6年前(2017-11-11)回复
  11. Please enter server names(like this:www.lamp.sh lamp.sh): Please enter website root directory(default:/data/www/www.xox.kim): Do you want to create database?[y/n]:(我怎么到这一步了 ) 已经下载github上的 并 git pull 了
    ocdpu6年前(2017-11-10)回复
  12. 很感谢秋大,如果没有你的脚本确实不知道如何去操作很多很多,因为您编写的脚本,才可以学到更多的知识,看到更多的信息,了解到如何去操作. 感谢您的脚本,没有你的脚本确实很难 很难啊.
    okok6年前(2017-11-06)回复
    • 客气了。其实网上还有别人写的脚本,你只是恰好看到了我写的而已。 加油,共勉!
      秋水逸冰6年前(2017-11-06)回复
  13. 不知道能否提供lnmp的安装脚本啊,谢谢您
    okok6年前(2017-11-06)回复
  14. LNMP有吗
    阿斯顿6年前(2017-11-06)回复
  15. 请问旧版本的lamp要怎么通过更新使用SSL 更新的有php apache等选项无法更新到使用ssl
    石头6年前(2017-11-05)回复
    • 这个旧版本是有多旧呢?最好还是先备份数据,卸载后重新安装一次吧。
      秋水逸冰6年前(2017-11-06)回复
      • 并不是很旧,昨天一顿折腾发现重新执行lamp好像网站数据也不会丢失,但是已安装的网站没有办法使用Let’s Encrypt,只好备份重装了一下
        石头6年前(2017-11-06)回复
        • 没错,即便是执行 lamp del 也只是删除配置文件而已,并不会真正去删除网站数据的。
          秋水逸冰6年前(2017-11-06)回复