Spaces:
dss11
/
Paused

ow / test_html_creation.sh
Your Name
2
a79ea2b
Raw History Blame Contribute Delete
1.63 kB
#!/bin/bash
echo "=== 测试 HTML 文件创建逻辑 ==="
# 模拟 start.sh 中的 HTML 创建逻辑
echo "1. 测试 /var/www/html 写入..."
mkdir -p /var/www/html 2>/dev/null
chmod 755 /var/www/html 2>/dev/null || echo "无法修改 /var/www/html 权限,将使用临时目录"
if cat > /var/www/html/test.html 2>/dev/null <<'EOF'
<!DOCTYPE html>
<html><head><title>Test</title></head><body><h1>Test</h1></body></html>
EOF
then
echo "✅ 成功写入 /var/www/html/test.html"
WEB_ROOT="/var/www/html"
rm -f /var/www/html/test.html
else
echo "❌ 无法写入 /var/www/html,测试临时目录..."
mkdir -p /tmp/www
if cat > /tmp/www/test.html <<'EOF'
<!DOCTYPE html>
<html><head><title>Test</title></head><body><h1>Test</h1></body></html>
EOF
then
echo "✅ 成功写入 /tmp/www/test.html"
WEB_ROOT="/tmp/www"
rm -f /tmp/www/test.html
else
echo "❌ 无法写入任何位置"
exit 1
fi
fi
echo "2. 选择的 WEB_ROOT: $WEB_ROOT"
echo "3. 测试 Nginx 配置生成..."
cat > /tmp/test_nginx.conf <<EOF
worker_processes auto;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 7860;
root $WEB_ROOT;
index index.html;
location / {
try_files \$uri \$uri/ =404;
}
}
}
EOF
if [ -f "/tmp/test_nginx.conf" ]; then
echo "✅ Nginx 配置文件生成成功"
echo "配置内容预览:"
grep "root" /tmp/test_nginx.conf
rm -f /tmp/test_nginx.conf
else
echo "❌ Nginx 配置文件生成失败"
fi
echo "=== 测试完成 ==="