通过WIN-ACME与PowerShell实现Jellfyin与MT photos自动更新SSL证书
0x00. 准备
首先去Github上下载Win-ACME对应的release,需要下载包括一个主程序和DNS验证的插件,DNS验证的插件根据自己使用的DNS服务商选择,按照Win-ACME主程序根目录下\Plugins\Validation\Dns结构新建文件夹,将DNS验证插件解压到\Dns文件夹下。
0x01. 配置wacs
启动wacs.exe,按照以下顺序完成配置:
Create certificate(full options) →Manual input→输入域名并回车→回车确认域名无误 →Single certificate→[dns] Create verification records in XXX DNS →Type/paste in console→输入对应DNS服务商的API ID→y →给这个API ID起个自己的名字并回车→输入对应DNS服务商的API KEY→y →给这个API KEY起个自己的名字并回车 →输入本地文件夹路径作为存放证书的位置→PEM encoded files(Apache,nginx,etc.)→None(不配置密码)→PFX archive→Type/paste in console(配置一个PFX的密码)。
此时会进行书申请,操作结束后查看本地是否存在新申请的证书,应该会存在pem文件和pfx文件。
0x02. Jellyfin配置
登录Jellyfin控制台,在网络中找到SSL证书位置,将该位置修改为上文中SSL证书存放位置(c:\xxx\aaa.bbb.ccc.pfx),将密码改为上文中PFX配置的密码。
新建一个ps1文件,复制以下内容,将-FilePath中路径替换成Jellyfin Server主程序目录下的Jellyfin.Windows.Tray.exe所在位置。
Stop-Process -Name "Jellyfin.Windows.Tray" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 5
Start-Process -FilePath "X:\XXX\Jellyfin\Server\jellyfin-windows-tray\Jellyfin.Windows.Tray.exe"
Write-Host "Jellyfin restarted!"0x03. MT photos配置
新建一个ps1文件,复制以下内容,按照如下位置替换相关变量。
$sourceDir:输入上文中Win-ACME配置的SSL证书存放位置。 $destDir:MT photos的证书存放位置,通常位于安装位置的\MT Photos Server\cache\ssl。 aaa.bbb.ccc-chain.pem:申请的aaa.bbb.ccc域名的fullchain证书。 aaa.bbb.ccc.crt:-chain证书重命名后的文件名。 aaa.bbb.ccc-key.pem:申请的aaa.bbb.ccc域名的key。 aaa.bbb.ccc.key:-key重命名后的文件名。 $exePath:mt-photos-server.exe主程序所在位置。 $workDir:MT photos根目录位置。
# Source and destination paths
$sourceDir = "X:\SSL"
$destDir = "X:\MT Photos Server\cache\ssl"
# Create destination directory if it does not exist
if (-not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir | Out-Null
Write-Host "Created destination directory: $destDir"
}
# Copy and rename certificate file
$srcCrt = Join-Path $sourceDir "aaa.bbb.ccc-chain.pem"
$dstCrt = Join-Path $destDir "aaa.bbb.ccc.crt"
if (Test-Path $srcCrt) {
Copy-Item -Path $srcCrt -Destination $dstCrt -Force
Write-Host "Copied: aaa.bbb.ccc-chain.pem -> aaa.bbb.ccc.crt"
}
else {
Write-Warning "Source file missing: $srcCrt"
}
# Copy and rename key file
$srcKey = Join-Path $sourceDir "aaa.bbb.ccc-key.pem"
$dstKey = Join-Path $destDir "aaa.bbb.ccc.key"
if (Test-Path $srcKey) {
Copy-Item -Path $srcKey -Destination $dstKey -Force
Write-Host "Copied: aaa.bbb.ccc-key.pem -> aaa.bbb.ccc.key"
}
else {
Write-Warning "Source file missing: $srcKey"
}
# --------------- MT Photos Server Process Control ---------------
$processName = "mt-photos-server"
$exePath = "X:\MT Photos Server\mt-photos-server.exe"
$workDir = "X:\MT Photos Server"
# Check if process exists
if (Get-Process -Name $processName -ErrorAction SilentlyContinue) {
Write-Host "`nProcess found, restarting..."
Stop-Process -Name $processName -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
}
else {
Write-Host "`nProcess not running, starting directly..."
}
$null = Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "`"$exePath`"", $workDir
Write-Host "`nSSL certificate update completed successfully."0x04. 向计划中添加脚本
重新打开wacs.exe,按照以下顺序修改配置:
Manage renewals→Edit renewal→Installation→Start external scripits or program →分两次输入上文中的脚本位置并回车,需要输入变量的时候直接回车即可。
等待全部脚本添加并执行无误后,会看到时候讲当前任务添加为计划任务,输入yes,然后输入当前用户的域和用域名(eg:DEV\USER),然后输入密码回车即可。
打开windows 的任务计划程序即可看到对应的Win-ACME计划任务。
通过WIN-ACME与PowerShell实现Jellfyin与MT photos自动更新SSL证书
https://blog.async.website/index.php/archives/3384/