Spaces:
Sleeping
Sleeping
File size: 1,062 Bytes
c88d551 |
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 |
#!/bin/bash
# Function to log messages
log_msg() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Test Nginx directories and permissions
test_nginx() {
log_msg "Testing Nginx configuration..."
# Test directory existence and permissions
directories=(
"/var/log/nginx"
"/var/lib/nginx"
"/var/lib/nginx/body"
"/run/nginx"
"/etc/nginx"
)
for dir in "${directories[@]}"; do
if [ ! -d "$dir" ]; then
log_msg "ERROR: Directory $dir does not exist"
return 1
fi
# Test write permissions
if ! touch "$dir/test_file" 2>/dev/null; then
log_msg "ERROR: Cannot write to $dir"
return 1
fi
rm -f "$dir/test_file"
log_msg "OK: $dir exists and is writable"
done
# Test Nginx configuration
if ! nginx -t; then
log_msg "ERROR: Nginx configuration test failed"
return 1
fi
log_msg "Nginx configuration test passed"
return 0
}
# Run the test
test_nginx |