当前位置: 首页 > wzjs >正文

贺州市住房与城乡建设局网站龙岗建设局网站

贺州市住房与城乡建设局网站,龙岗建设局网站,网页设计软件dw全称,做pc端网站渠道现在免费的SSL证书三个月就到期了,为了方便写了一个更新SSL证书的程序,把程序和xxx_nginx.zip的证书放在同一目录下,先解压ssl文件,然后上传到服务器,最后复制到nginx的路径下。一台服务器有多个ssl证书,最…

现在免费的SSL证书三个月就到期了,为了方便写了一个更新SSL证书的程序,把程序和xxx_nginx.zip的证书放在同一目录下,先解压ssl文件,然后上传到服务器,最后复制到nginx的路径下。一台服务器有多个ssl证书,最好ssl有效期控制在同一天这样方便更新,只需要将多个ssl压缩包和程序放在一起即可。

代码如下:

Install-Package DotNetZip -Version 1.16.0
Install-Package SSH.NET -Version 2024.2.0
using Ionic.Zip;
using Renci.SshNet;
using System;
using System.IO;class Program
{static void Main(){Console.WriteLine("即将启动SSL证书更新,按任意键继续。");Console.ReadKey();string currentDir = Directory.GetCurrentDirectory();var result = UnzipFile(currentDir);if (!result){Console.WriteLine("文件提取失败");Console.WriteLine("按任意键退出");Console.ReadKey();return;}Console.WriteLine("文件提取完成");Console.WriteLine("按任意键继续");Console.ReadKey();SSHClient(currentDir);Console.WriteLine("按任意键退出任务");Console.ReadKey();}public static bool UnzipFile(string currentDir){var files = Directory.GetFiles(currentDir, "*nginx.zip");if (files.Length == 0){return false;}foreach (string zipFile in files){try{using (ZipFile zip = ZipFile.Read(zipFile, new ReadOptions { Encoding = System.Text.Encoding.Default })){foreach (ZipEntry entry in zip){if (entry.IsDirectory) continue;string ext = Path.GetExtension(entry.FileName).ToLower();if (ext == ".key" || ext == ".pem")//根据自己要求,也可以把所有文件都解压出啦{entry.Extract(currentDir, ExtractExistingFileAction.OverwriteSilently);}}}var path = Path.Combine(currentDir, Path.GetFileNameWithoutExtension(zipFile));foreach (string file in Directory.GetFiles(path)){string destFile = Path.Combine(currentDir, Path.GetFileName(file));File.Copy(file, destFile, true);  // true表示如果文件已存在则覆盖}Directory.Delete(path, true);}catch (Exception ex){Console.WriteLine($"解压失败:{zipFile}\n错误信息:{ex.Message}");return false;}}return true;}public static void SSHClient(string currentDir){string host = "host";  // 服务器地址string username = "username";  // 登录用户名string password = "password";  // 登录密码string remoteFilePath = "/home/username/ssl/";  // 远程服务器上的目标文件路径string sudoPassword = "sudoPassword";  // sudo 密码try{// 上传文件到服务器using (var sftp = new SftpClient(host, username, password)){sftp.Connect();Console.WriteLine("成功连接到FTP服务器");var allFiles = Directory.GetFiles(currentDir)//根据自己要求过滤文件.Where(file => file.EndsWith(".key", StringComparison.OrdinalIgnoreCase) ||file.EndsWith(".pem", StringComparison.OrdinalIgnoreCase));foreach (var item in allFiles){using (var fileStream = File.OpenRead(item)){sftp.UploadFile(fileStream, $"{remoteFilePath + Path.GetFileName(item)}");Console.WriteLine($"{Path.GetFileName(item)}文件上传成功!");}} sftp.Disconnect();Console.WriteLine("FTP服务器断开连接");Console.WriteLine("按任意键继续");Console.ReadKey();}// 执行sudo命令using (var sshClient = new SshClient(host, username, password)){sshClient.Connect();Console.WriteLine("成功连接到SSH服务器");// 通过 SSH 执行需要 sudo 的命令string sudoCommand = "echo " + sudoPassword + " | sudo -S /home/username/update_ssl.sh"; // 这里用 echo 将密码传递给 sudovar command = sshClient.RunCommand(sudoCommand);if (!string.IsNullOrEmpty(command.Error)){Console.WriteLine("命令执行消息:"+command.Error);}Console.WriteLine("命令执行结果: " + command.Result);sshClient.Disconnect();Console.WriteLine("SSH服务器断开连接");}}catch (Exception ex){Console.WriteLine("错误: " + ex.Message);}}
}

update_ssl.sh 代码如下

#!/bin/bash
# 复制证书文件(需root权限)
sudo cp /home/username/ssl/* /etc/nginx/conf.d/ssl/# 检查配置语法并重载
if sudo nginx -t; thensudo nginx -s reloadecho "SSL证书更新成功!"
elseecho "Nginx配置检查失败,请排查错误!"exit 1
fi

配置免密sudo‌

echo sudoPassword | sudo -S ./update_ssl.sh #替代安全方案‌
#在/etc/sudoers中添加NOPASSWD规则,允许特定命令无需密码:
username ALL=(ALL) NOPASSWD: /home/username/update_ssl.sh

文章转载自:

http://kExT6eih.Lbrwm.cn
http://wAqpzWH0.Lbrwm.cn
http://S0dsnbi1.Lbrwm.cn
http://b6p89dKN.Lbrwm.cn
http://dQ3E0EUU.Lbrwm.cn
http://hp758hXz.Lbrwm.cn
http://fGrblvTX.Lbrwm.cn
http://yGA9Ltv6.Lbrwm.cn
http://m3JaPrPv.Lbrwm.cn
http://iu2Y8NHw.Lbrwm.cn
http://fDiWWRuH.Lbrwm.cn
http://eOCivbdY.Lbrwm.cn
http://gXI7oNxR.Lbrwm.cn
http://01DIqfME.Lbrwm.cn
http://1BFB96BR.Lbrwm.cn
http://93oRnP6A.Lbrwm.cn
http://xX1haVN3.Lbrwm.cn
http://TVBSmqgl.Lbrwm.cn
http://pyLg2Syn.Lbrwm.cn
http://4jKQvxHG.Lbrwm.cn
http://HBPIBo6B.Lbrwm.cn
http://B3A8VY31.Lbrwm.cn
http://ZIthv46Q.Lbrwm.cn
http://NWUlSW7s.Lbrwm.cn
http://PPcH4eTH.Lbrwm.cn
http://NcZeJhEC.Lbrwm.cn
http://7pH5wuRs.Lbrwm.cn
http://q9sg4r4r.Lbrwm.cn
http://cAO9Ywpd.Lbrwm.cn
http://8yqdSuaQ.Lbrwm.cn
http://www.dtcms.com/wzjs/689653.html

相关文章:

  • 郑州腾石建站前程无忧网最新招聘信息
  • 中小企业网站设计外贸建站推广多少钱
  • 电子商务网站建设概述seo sem优化
  • 如何利用NAS做网站赚钱软件哪个赚钱多又快
  • 阿坝州城乡建设网站早教网站源码
  • 以学校为目标做网站策划书免费做试用的网站
  • 做班级网站的目的网站建设金牛万达
  • 网站推广的优化商城网站建设论坛
  • 哪个网站是自己销售建网站需要什么语言
  • 公司用自己机房做网站备案创业项目大全
  • 确定网站主题然后规划网站建设电子 东莞网站建设
  • 河北邢台手机网站建设南充房产网58同城
  • 网站开发预算表搜索引擎优化seo论文
  • 网页制作模块素材seo标题优化关键词
  • 注册新公司网上核名流程深圳网站建设zhaoseo
  • 设计网站用什么语言怎样做金融网站
  • 什么网站做推广好网站建设 太原
  • 校园网站制作建设网站经验
  • 汉字域名网站程序开发接单
  • 做网站一年费用常州网站建设公司咨询
  • 做网编去网站还是工作室好网站的开发与设计
  • 网站备案多久一次动态视觉设计网站
  • 设计网站欣赏表白网站制作源码
  • 如何做一起好的视频宣传自己的网站手机网站建设 的作用
  • 昆明做网站词排名优化广告设计创意培训
  • 抚州的电子商务网站建设公司外包公司网站开发
  • 禁止百度收录的网站wordpress邮箱配置文件
  • 公司禁用网站怎么做郑州抖音推广
  • 建设工程消防网站进入程序华大 网站建设
  • 本网站维护升级搜索引擎优化的概念是什么