81 lines
2.7 KiB
Bash
Executable file
81 lines
2.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Script to fix VSCode rate limiting issue (429 Too Many Requests)
|
|
# Updates nginx.conf to increase rate limits for VSCode
|
|
|
|
set -e
|
|
|
|
SERVER_IP="147.45.152.129"
|
|
SERVER_USER="root"
|
|
|
|
echo "🔧 Fixing VSCode rate limiting configuration..."
|
|
echo "Server: $SERVER_IP"
|
|
echo ""
|
|
|
|
ssh "$SERVER_USER@$SERVER_IP" << 'ENDSSH'
|
|
set -e
|
|
|
|
echo "📋 Backing up current nginx.conf..."
|
|
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup.$(date +%Y%m%d_%H%M%S)
|
|
|
|
echo ""
|
|
echo "🔍 Checking current rate limit configuration..."
|
|
if grep -q "limit_req_zone.*vscode_general" /etc/nginx/nginx.conf; then
|
|
echo "Current vscode_general rate limit:"
|
|
grep "limit_req_zone.*vscode_general" /etc/nginx/nginx.conf
|
|
echo ""
|
|
|
|
echo "📝 Updating rate limit from 30r/m to 200r/m..."
|
|
# Update vscode_general rate limit
|
|
sed -i 's/limit_req_zone $binary_remote_addr zone=vscode_general:10m rate=30r\/m;/limit_req_zone $binary_remote_addr zone=vscode_general:10m rate=200r\/m;/' /etc/nginx/nginx.conf
|
|
|
|
echo "✅ Rate limit updated"
|
|
echo ""
|
|
echo "New vscode_general rate limit:"
|
|
grep "limit_req_zone.*vscode_general" /etc/nginx/nginx.conf
|
|
else
|
|
echo "⚠️ vscode_general rate limit zone not found"
|
|
echo "Adding rate limiting zones..."
|
|
|
|
# Find http block and add rate limiting zones
|
|
if grep -q "^http {" /etc/nginx/nginx.conf; then
|
|
sed -i '/^http {/a\ # Rate limiting zones for VSCode Server\n limit_req_zone $binary_remote_addr zone=vscode_general:10m rate=200r/m;\n limit_req_zone $binary_remote_addr zone=vscode_login:10m rate=5r/m;' /etc/nginx/nginx.conf
|
|
echo "✅ Rate limiting zones added"
|
|
else
|
|
echo "❌ Could not find http block in nginx.conf"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "📊 Testing nginx configuration syntax..."
|
|
/usr/sbin/nginx -t
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo ""
|
|
echo "🔄 Reloading nginx..."
|
|
systemctl reload nginx
|
|
echo "✅ nginx reloaded successfully"
|
|
else
|
|
echo "❌ nginx configuration test failed"
|
|
echo "Restoring backup..."
|
|
cp /etc/nginx/nginx.conf.backup.* /etc/nginx/nginx.conf
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "📊 Final rate limit configuration:"
|
|
grep "limit_req_zone.*vscode" /etc/nginx/nginx.conf
|
|
|
|
ENDSSH
|
|
|
|
echo ""
|
|
echo "✅ Done!"
|
|
echo ""
|
|
echo "📝 Changes made:"
|
|
echo " - vscode_general rate limit: 30r/m → 200r/m"
|
|
echo " - Static files are excluded from rate limiting (in vscode-nginx.conf)"
|
|
echo ""
|
|
echo "🌐 Test VSCode Server at:"
|
|
echo " https://vscode.mnemo-cards.online/"
|
|
|