# ========================================================================= # IIS サイト設定スクリプト: UDUKI-PC\サイト\MusicStreaming # ========================================================================= [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $ErrorActionPreference = "Continue" Write-Host "=======================================================" -ForegroundColor Cyan Write-Host " IIS サイト [MusicStreaming] の作成・公開を開始します " -ForegroundColor Cyan Write-Host "=======================================================" -ForegroundColor Cyan Import-Module WebAdministration -ErrorAction SilentlyContinue $appcmd = "$env:windir\system32\inetsrv\appcmd.exe" $siteName = "MusicStreaming" $port = 8081 $physicalPath = "C:\docker\music" # 1. 権限設定 (公開ディレクトリのみ) Write-Host "`n[1/4] フォルダーのアクセス権限を設定中..." -ForegroundColor Yellow icacls "$physicalPath" /grant "IIS_IUSRS:(OI)(CI)RX" /T | Out-Null Write-Host "アクセス権限を付与しました。" -ForegroundColor Green # 2. 既存の不整合なサイト・アプリプールを完全に強制削除 Write-Host "`n[2/4] 既存のサイト・アプリプールを整理中..." -ForegroundColor Yellow try { & $appcmd stop site "$siteName" 2>$null } catch {} try { & $appcmd delete site "$siteName" 2>$null } catch {} try { & $appcmd delete apppool "$siteName" 2>$null } catch {} try { Remove-Item "IIS:\Sites\$siteName" -Recurse -Force -ErrorAction SilentlyContinue } catch {} try { Remove-Item "IIS:\AppPools\$siteName" -Recurse -Force -ErrorAction SilentlyContinue } catch {} Write-Host "整理が完了しました。" -ForegroundColor Green # 3. アプリケーションプールの作成 (マネージドコードなし) Write-Host "`n[3/4] アプリケーションプール '$siteName' を作成中..." -ForegroundColor Yellow $pool = New-Item "IIS:\AppPools\$siteName" -Force Set-ItemProperty "IIS:\AppPools\$siteName" -Name "managedRuntimeVersion" -Value "" Set-ItemProperty "IIS:\AppPools\$siteName" -Name "autoStart" -Value $true Write-Host "アプリケーションプールを作成しました。" -ForegroundColor Green # 4. サイトの作成とバインディング Write-Host "`n[4/4] サイト '$siteName' を作成・起動中 (ポート: $port)..." -ForegroundColor Yellow New-WebSite -Name $siteName -Port $port -PhysicalPath $physicalPath -ApplicationPool $siteName | Out-Null Start-Sleep -Seconds 1 try { Start-WebSite -Name $siteName -ErrorAction SilentlyContinue } catch {} $finalSite = Get-WebSite -Name $siteName -ErrorAction SilentlyContinue $state = if ($finalSite) { $finalSite.State } else { "Unknown" } Write-Host "`n=======================================================" -ForegroundColor Green Write-Host " [完了] UDUKI-PC\サイト\$siteName の作成が完了しました!" -ForegroundColor Green Write-Host " ・サイト名: $siteName" -ForegroundColor Green Write-Host " ・状態: $state" -ForegroundColor Green Write-Host " ・ポート: $port" -ForegroundColor Green Write-Host " ・物理パス: $physicalPath" -ForegroundColor Green Write-Host " ・アプリケーションプール: $siteName" -ForegroundColor Green Write-Host " ・ローカルURL: http://localhost:$port/" -ForegroundColor Green Write-Host " ・公開URL: https://mymusic.armonica-vps.work/" -ForegroundColor Green Write-Host "=======================================================" -ForegroundColor Green