-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_nginx_status.ps1
More file actions
142 lines (119 loc) · 4.79 KB
/
check_nginx_status.ps1
File metadata and controls
142 lines (119 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Quick Nginx Status Check Script
$ErrorActionPreference = "Continue"
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Nginx Status Check" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check if Nginx is installed
Write-Host "[1] Checking Nginx Installation..." -ForegroundColor Yellow
$nginxPaths = @(
"C:\nginx\nginx.exe",
"C:\nginx-1.28.0\nginx.exe",
"C:\nginx-1.27.0\nginx.exe",
"C:\nginx-1.26.0\nginx.exe",
"C:\nginx-1.25.0\nginx.exe",
"C:\nginx-1.24.0\nginx.exe"
)
$nginxFound = $false
$nginxPath = $null
foreach ($path in $nginxPaths) {
if (Test-Path $path) {
$nginxPath = $path
$nginxFound = $true
Write-Host " ✓ Nginx found at: $path" -ForegroundColor Green
break
}
}
if (-not $nginxFound) {
Write-Host " ✗ Nginx is not installed" -ForegroundColor Red
Write-Host " → Run: .\install_nginx.ps1" -ForegroundColor Cyan
Write-Host ""
exit 1
}
Write-Host ""
# Check if Nginx is running
Write-Host "[2] Checking Nginx Process..." -ForegroundColor Yellow
$nginxProcesses = Get-Process -Name "nginx" -ErrorAction SilentlyContinue
if ($nginxProcesses) {
Write-Host " ✓ Nginx is running ($($nginxProcesses.Count) process(es))" -ForegroundColor Green
$nginxProcesses | ForEach-Object {
Write-Host " - PID: $($_.Id), Started: $($_.StartTime)" -ForegroundColor Gray
}
} else {
Write-Host " ✗ Nginx is not running" -ForegroundColor Red
Write-Host " → Run: .\start.ps1" -ForegroundColor Cyan
}
Write-Host ""
# Check port 80
Write-Host "[3] Checking Port 80..." -ForegroundColor Yellow
try {
$port80Check = Test-NetConnection -ComputerName localhost -Port 80 -WarningAction SilentlyContinue -InformationLevel Quiet
if ($port80Check) {
Write-Host " ✓ Port 80 is open" -ForegroundColor Green
# Try to access site
try {
$response = Invoke-WebRequest -Uri "http://localhost" -TimeoutSec 3 -UseBasicParsing -ErrorAction Stop
Write-Host " ✓ Site is accessible (Status: $($response.StatusCode))" -ForegroundColor Green
} catch {
Write-Host " ⚠ Port 80 is open but site may not be responding: $_" -ForegroundColor Yellow
}
} else {
Write-Host " ✗ Port 80 is not open" -ForegroundColor Red
}
} catch {
Write-Host " ✗ Error checking port 80: $_" -ForegroundColor Red
}
Write-Host ""
# Check Nginx configuration
Write-Host "[4] Checking Nginx Configuration..." -ForegroundColor Yellow
$nginxDir = Split-Path $nginxPath -Parent
$nginxConfPath = Join-Path $nginxDir "conf\nginx.conf"
if (Test-Path $nginxConfPath) {
Write-Host " ✓ Configuration file exists: $nginxConfPath" -ForegroundColor Green
# Test configuration
Set-Location $nginxDir
$configTest = & $nginxPath -t 2>&1
Set-Location $PSScriptRoot
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ Configuration is valid" -ForegroundColor Green
} else {
Write-Host " ✗ Configuration has errors:" -ForegroundColor Red
$configTest | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
}
} else {
Write-Host " ✗ Configuration file not found: $nginxConfPath" -ForegroundColor Red
Write-Host " -> Copy nginx_production.conf to $nginxConfPath" -ForegroundColor Cyan
}
Write-Host ""
# Check Nginx logs
Write-Host "[5] Checking Nginx Logs..." -ForegroundColor Yellow
$nginxLogsDir = Join-Path $nginxDir "logs"
if (Test-Path $nginxLogsDir) {
Write-Host " ✓ Logs directory exists: $nginxLogsDir" -ForegroundColor Green
$errorLog = Join-Path $nginxLogsDir "error.log"
$accessLog = Join-Path $nginxLogsDir "access.log"
if (Test-Path $errorLog) {
$errorLogSize = (Get-Item $errorLog).Length
Write-Host " ✓ Error log exists ($errorLogSize bytes)" -ForegroundColor Green
# Show last 5 error lines if any
$lastErrors = Get-Content $errorLog -Tail 5 -ErrorAction SilentlyContinue
if ($lastErrors) {
Write-Host " Last errors:" -ForegroundColor Yellow
$lastErrors | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
}
} else {
Write-Host " ⚠ Error log not found" -ForegroundColor Yellow
}
if (Test-Path $accessLog) {
$accessLogSize = (Get-Item $accessLog).Length
Write-Host " ✓ Access log exists ($accessLogSize bytes)" -ForegroundColor Green
} else {
Write-Host " ⚠ Access log not found" -ForegroundColor Yellow
}
} else {
Write-Host " ✗ Logs directory not found: $nginxLogsDir" -ForegroundColor Red
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""