#!/bin/bash # 3D素材系统 - Nginx 域名配置脚本 (CentOS 7) # 域名: 3D.YYDD.AI # 后端服务: http://localhost:2320 echo "==========================================" echo " 配置 Nginx 反向代理 (CentOS 7)" echo " 域名: 3D.YYDD.AI" echo "==========================================" # 1. 安装 Nginx echo "1. 检查并安装 Nginx..." if ! command -v nginx &> /dev/null; then echo "安装 Nginx..." yum install -y epel-release yum install -y nginx else echo "Nginx 已安装: $(nginx -v 2>&1)" fi # 2. 创建配置目录(如果不存在) mkdir -p /etc/nginx/conf.d # 3. 创建 Nginx 配置文件 echo "" echo "2. 创建 Nginx 配置..." cat > /etc/nginx/conf.d/3d-yydd-ai.conf << '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; # 超时设置(支持大文件上传,3小时) client_body_timeout 10800s; client_header_timeout 10800s; send_timeout 10800s; proxy_connect_timeout 10800s; proxy_send_timeout 10800s; proxy_read_timeout 10800s; # 缓冲区设置 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; # 增加超时时间(3小时) proxy_connect_timeout 10800s; proxy_send_timeout 10800s; proxy_read_timeout 10800s; } } EOF echo "✅ Nginx 配置文件已创建: /etc/nginx/conf.d/3d-yydd-ai.conf" # 4. 配置 SELinux(允许 Nginx 网络连接) echo "" echo "3. 配置 SELinux..." if command -v setsebool &> /dev/null; then setsebool -P httpd_can_network_connect 1 echo "✅ SELinux 配置完成" else echo "⚠️ SELinux 工具未找到,跳过" fi # 5. 配置防火墙 echo "" echo "4. 配置防火墙..." if command -v firewall-cmd &> /dev/null; then firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload echo "✅ 防火墙配置完成" else echo "⚠️ firewalld 未运行,跳过" fi # 6. 测试 Nginx 配置 echo "" echo "5. 测试 Nginx 配置..." if nginx -t; then echo "✅ Nginx 配置测试通过" else echo "❌ Nginx 配置测试失败" exit 1 fi # 7. 启动 Nginx echo "" echo "6. 启动 Nginx..." systemctl enable nginx systemctl restart nginx sleep 2 if systemctl is-active --quiet nginx; then echo "✅ Nginx 已成功启动" else echo "❌ Nginx 启动失败" systemctl status nginx exit 1 fi # 8. 测试代理 echo "" echo "7. 测试反向代理..." if curl -s -o /dev/null -w "%{http_code}" http://localhost:80 | grep -q "307\|200\|301"; then echo "✅ 反向代理工作正常" else echo "⚠️ 反向代理可能有问题,请检查后端服务" fi echo "" echo "==========================================" echo " ✅ 配置完成!" echo "==========================================" echo "" echo "📋 配置信息:" echo " 域名: 3D.YYDD.AI" echo " 后端: http://localhost:2320" echo " 上传限制: 无限制" echo " 超时时间: 10800秒(3小时)" 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. 测试访问: curl -I http://3d.yydd.ai" echo " 3. 如需 HTTPS,请安装 certbot:" echo " yum install -y certbot python2-certbot-nginx" echo " certbot --nginx -d 3d.yydd.ai -d www.3d.yydd.ai" echo "" echo "✅ 完成!"