Files
nginxserver/scripts/enable_large_upload.sh
2026-07-16 13:03:11 +08:00

37 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 允许大文件上传(最大 2GB
# 全局 http 块 + server 块同时设置
# 1. nginx.conf http 块加全局默认值
if ! grep -q 'client_max_body_size' /etc/nginx/nginx.conf; then
sed -i '/gzip_types text\/plain/i\ client_max_body_size 2048m;\n client_body_timeout 300s;' /etc/nginx/nginx.conf
echo "[OK] nginx.conf: client_max_body_size 2048m"
else
echo "[SKIP] nginx.conf already has client_max_body_size"
fi
# 2. 每个 server 块也加上(覆盖可能的全局设置)
for f in /etc/nginx/conf.d/*.conf; do
if ! grep -q 'client_max_body_size' "$f"; then
sed -i '/server_name/a\ client_max_body_size 2048m;' "$f"
echo "[OK] $(basename $f): added"
else
echo "[SKIP] $(basename $f): already has"
fi
done
# 3. 更新 Python API 模板(未来新增规则自动带此配置)
TEMPLATE="/opt/nginx-api/services/nginx_service.py"
if [ -f "$TEMPLATE" ] && ! grep -q 'client_max_body_size' "$TEMPLATE"; then
sed -i '/server_name {domain};/a\ client_max_body_size 2048m;' "$TEMPLATE"
systemctl restart nginx-api
echo "[OK] Python template updated + API restarted"
else
echo "[SKIP] Python template already has client_max_body_size"
fi
# 4. 验证
echo ""
echo "=== nginx -t ==="
nginx -t && systemctl reload nginx && echo "=== DONE ==="