gongxiangp2/setup-nginx-domain.sh
2025-10-26 09:11:04 +08:00

152 lines
4.0 KiB
Bash
Executable File
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
# 3D素材系统 - Nginx 域名配置脚本
# 域名: 3D.YYDD.AI
# 后端服务: http://localhost:2320
echo "=========================================="
echo " 配置 Nginx 反向代理"
echo " 域名: 3D.YYDD.AI"
echo "=========================================="
# 1. 安装 Nginx(如果未安装)
echo "1. 检查并安装 Nginx..."
if ! command -v nginx &> /dev/null; then
echo "安装 Nginx..."
apt-get update
apt-get install -y nginx
else
echo "Nginx 已安装: $(nginx -v 2>&1)"
fi
# 2. 创建 Nginx 配置文件
echo ""
echo "2. 创建 Nginx 配置..."
cat > /etc/nginx/sites-available/3d.yydd.ai << 'EOF'
# 3D 素材系统 - Nginx 配置
# 域名: 3D.YYDD.AI 和 3d.yydd.ai
server {
listen 80;
listen [::]:80;
server_name 3d.yydd.ai 3D.YYDD.AI www.3d.yydd.ai;
# 日志文件
access_log /var/log/nginx/3d-yydd-access.log;
error_log /var/log/nginx/3d-yydd-error.log;
# 客户端请求体大小限制(设置为 0 表示不限制)
client_max_body_size 0;
# 超时设置(支持大文件上传)
client_body_timeout 3600s;
client_header_timeout 3600s;
send_timeout 3600s;
proxy_connect_timeout 3600s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
# 缓冲区设置
client_body_buffer_size 128k;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
location / {
# 反向代理到本地 2320 端口(FRP 穿透后的 NAS 服务)
proxy_pass http://localhost:2320;
# 代理头设置
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket 支持(如果需要)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 禁用缓冲以支持大文件上传
proxy_request_buffering off;
proxy_buffering off;
}
# API 路由特殊处理(确保上传不受限制)
location /api/ {
proxy_pass http://localhost:2320;
# 代理头设置
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 特别针对上传的设置
proxy_request_buffering off;
proxy_buffering off;
client_max_body_size 0;
# 增加超时时间
proxy_connect_timeout 3600s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
}
}
EOF
echo "✅ Nginx 配置文件已创建: /etc/nginx/sites-available/3d.yydd.ai"
# 3. 启用站点
echo ""
echo "3. 启用站点..."
ln -sf /etc/nginx/sites-available/3d.yydd.ai /etc/nginx/sites-enabled/
echo "✅ 站点已启用"
# 4. 测试 Nginx 配置
echo ""
echo "4. 测试 Nginx 配置..."
if nginx -t; then
echo "✅ Nginx 配置测试通过"
else
echo "❌ Nginx 配置测试失败"
exit 1
fi
# 5. 重启 Nginx
echo ""
echo "5. 重启 Nginx..."
systemctl restart nginx
systemctl enable nginx
if systemctl is-active --quiet nginx; then
echo "✅ Nginx 已成功启动"
else
echo "❌ Nginx 启动失败"
systemctl status nginx
exit 1
fi
echo ""
echo "=========================================="
echo " ✅ 配置完成!"
echo "=========================================="
echo ""
echo "📋 配置信息:"
echo " 域名: 3D.YYDD.AI"
echo " 后端: http://localhost:2320"
echo " 上传限制: 无限制"
echo " 超时时间: 3600秒(1小时)"
echo ""
echo "🌐 访问地址:"
echo " http://3d.yydd.ai"
echo " http://3D.YYDD.AI"
echo ""
echo "📝 下一步:"
echo " 1. 确保域名 3D.YYDD.AI 已解析到 180.97.221.140"
echo " 2. 如需 HTTPS,请运行: certbot --nginx -d 3d.yydd.ai -d www.3d.yydd.ai"
echo ""
echo "✅ 完成!"