oneinstack申请免费的R3 域名证书

285 阅读3分钟

OneinStack 是知名 Linux 技术博客 LinuxEye 推出的一个可以一键安装 LNMP(Linux + NGINX + MySQL + PHP)、LAMP(Linux + Apache + MySQL + PHP)、LNMPA(Linux + NGINX + MySQL + PHP + Apache)等建站环境的一键安装包。主要是提供了一个可视化页面,可以直接在页面上选择自己想要的配置,然后自动生成安装命令,然后就等待自动安装完成就行

oneinstack 官网 linux 下载oneinstack wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar -xvf oneinstack-full.tar.gz

oneinstack集成了acme.sh 工具,可以用 vhost.sh 脚本文件直接申请免费的R3证书,并自动创建计划任务,检测并更新证书到期时间。 oneinstack的文件目录如下:

addons.sh 
backup_setup.sh # 备份设置
backup.sh # 执行备份
config
include
init.d
install.log
install.sh # oneinstack环境安装脚本
LICENSE
options.conf # 配置信息存放文件
pureftpd_vhost.sh # ftp管理
README.md
reset_db_root_password.sh # 重置数据库root密码
src # 安装过程使用源码安装,将会把源码文件下载到这个文件夹
tools
uninstall.sh # oneinstack环境卸载脚本
upgrade.sh # 各种插件升级脚本
versions.txt
vhost.sh # 域名证书申请脚本

证书申请 开始之前需要首先购买、备案、并解析域名。 备案帮助文档 解析域名帮助文档 进入 oneinstack 工作目录,使用 root 权限执行 vhost.sh 文件 ./vhost.sh

  • 选择生成网站配置文件的方式
What Are You Doing?
    1. Use HTTP Only
    2. Use your own SSL Certificate and Key
    3. Use Let's Encrypt to Create SSL Certificate and Key
    q. Exit
Please input the correct option: 3
  1. 不使用证书,直接生成网站配置文件
  2. 使用自定义证书,这个同样需要填写域名等信息,但是脚本不会去R3官网申请证书,配置文件生成后需要手动将自己的证书放在配置文件指定的位置中
  3. 使用 " Let's Encrypt " 提供的免费证书
  • 输入域名、设置网站根目录
Please input domain(example: www.example.com): demo.leorain.cn
domain=demo.leorain.cn

Please input the directory for the domain:demo.leorain.cn :
(Default directory: /data/wwwroot/demo.leorain.cn): 
Virtual Host Directory=/data/wwwroot/demo.leorain.cn

Create Virtul Host directory......
set permissions of Virtual Host directory......

网站根目录 网站根目录对应的是nginx配置中的 root 值,不同的项目对应的 root 路径不同,且对应的索引文件也不同,例如:1、普通的独立站,使用 laravel 的 blade 模板渲染,则需要 root 路径指向 laravel 的 public 目录,索引文件指向 index.php ,并将 quest_string 从定向到 index.php 文件。2、前后端分离项目,需要将网站根目录指向前端的根路径:[web_root]/dist/ ,索引文件指向 index.html ,并将 query_string 指向 index.html

Do you want to add hotlink protection? [y/n]: n

Allow Rewrite rule? [y/n]: y

Please input the rewrite of programme :
wordpress,opencart,magento2,drupal,joomla,codeigniter,laravel
thinkphp,pathinfo,discuz,typecho,ecshop,nextcloud,zblog,whmcs rewrite was exist.
(Default rewrite: other): laravel
You choose rewrite=laravel

Allow Nginx/Tengine/OpenResty access_log? [y/n]: y
You access log file=/data/wwwlogs/demo.leorain.cn_nginx.log

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......

使用oneinstack里面的acme模块申请的证书,会自动生成续费计划任务。

  • sudo su 切换root用户申请的证书,自动续费配置文件在/root/.acme.sh/ 里面
7 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
  • sudo vhost.sh
7 0 * * * "/home/ubuntu/.acme.sh"/acme.sh --cron --home "/home/ubuntu/.acme.sh" > /dev/null

oneinstack自带的acme.sh会因为nginx配置问题, 导致自动续费失败,在网站的nginx配置最后添加以下配置,重载nginx即可自动续费

#  ACME_CRON_NGINX_WELLKNOW BEGIN ANSIBLE MANAGED BLOCK
location /.well-known {
  allow all;
}
#  ACME_CRON_NGINX_WELLKNOW END ANSIBLE MANAGED BLOCK

博客原文