默认安装tenginx 后,由于 nginx -V 命令中缺乏--with-http_ssl_module 导致。一般会提议安装时加上参数重新编译解决。
本题为了避免重新编译,通过shell脚本欺骗 certbot 实现HTTPS证书签发。
certbot通过python命令执行 nginx -c /etc/nginx/nginx.conf -t ,并获取错误输出通道的记录。正则判断是否存在字符串 “ --with-http_ssl_module ”
1.通过which nginx 查找nginx可执行文件位置。
2.将此文件改名如 mv /bin/nginx /bin/nginx_app
3./bin/nginx替换成shell脚本 ,并增加可执行权限 chmod +x /bin/nginx
4. 执行证书签发流程 certbot --nginx
#!/bin/bash
arg=$@
echo "${arg}" | grep -V
if [ $? -eq 0 ] ;then
/usr/local/nginx/sbin/nginx $@
echo --with-http_ssl_module >&2
else /usr/local/nginx/sbin/nginx $@
fi