# 随机跳转域名配置大全

我来为你实现 `random.shumengya.top` 的各种随机跳转方案，每种都很好玩！

## 1. **基础随机跳转（Nginx + Lua）**

### 1.1 安装 **Open**Resty（带 Lua 的 Nginx）
```bash
# Ubuntu/Debian
sudo apt install openresty

# 或者编译 Nginx 时加入 Lua 模块
```

### 1.2 配置基础随机跳转
```nginx
# /usr/local/openresty/nginx/conf/conf.d/random-redirect.conf
server {
    listen 80;
    server_name random.shumengya.top;
    
    # 使用 Lua 实现随机跳转
    set_by_lua_block $random_target {
        local targets = {
            "https://www.google.com",
            "https://github.com",
            "https://stackoverflow.com",
            "https://news.ycombinator.com",
            "https://www.wikipedia.org",
            "https://www.youtube.com",
            "https://twitter.com",
            "https://www.reddit.com",
            "https://www.zhihu.com",
            "https://www.bilibili.com"
        }
        math.randomseed(ngx.time() + ngx.worker.pid())
        local idx = math.random(#targets)
        return targets[idx]
    }
    
    return 301 $random_target;
}
```

## 2. **时间条件随机跳转**

### 2.1 根据时间段跳转
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    set_by_lua_block $target {
        local ngx_time = ngx.localtime()  -- 格式: 2024-01-15 14:30:45
        local hour = tonumber(string.sub(ngx_time, 12, 13))
        local minute = tonumber(string.sub(ngx_time, 15, 16))
        
        -- 根据时间选择目标
        if hour >= 6 and hour < 12 then
            -- 早上：新闻类
            local morning_sites = {
                "https://news.google.com",
                "https://www.bbc.com/news",
                "https://www.reuters.com",
                "https://www.npr.org"
            }
            return morning_sites[math.random(#morning_sites)]
        elseif hour >= 12 and hour < 18 then
            -- 下午：技术类
            local afternoon_sites = {
                "https://github.com/trending",
                "https://news.ycombinator.com",
                "https://stackoverflow.com",
                "https://dev.to"
            }
            return afternoon_sites[math.random(#afternoon_sites)]
        elseif hour >= 18 and hour < 22 then
            -- 晚上：娱乐类
            local evening_sites = {
                "https://www.youtube.com",
                "https://www.bilibili.com",
                "https://www.netflix.com",
                "https://www.twitch.tv"
            }
            return evening_sites[math.random(#evening_sites)]
        else
            -- 深夜：放松类
            local night_sites = {
                "https://www.calm.com",
                "https://asoftmurmur.com",
                "https://www.rainymood.com",
                "https://stars.chromeexperiments.com"
            }
            return night_sites[math.random(#night_sites)]
        end
    }
    
    return 301 $target;
}
```

### 2.2 根据星期几跳转
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    set_by_lua_block $target {
        local days = {
            ["Sunday"] = {
                "https://www.churchofjesuschrist.org",
                "https://www.sabbath.org",
                "https://www.biblegateway.com"
            },
            ["Monday"] = {
                "https://www.monday.com",
                "https://www.productivity.com",
                "https://www.todoist.com"
            },
            ["Tuesday"] = {
                "https://www.taco.com",
                "https://www.twosday.com",  -- Two's day
                "https://www.techrepublic.com"
            },
            ["Wednesday"] = {
                "https://en.wikipedia.org/wiki/Hump_Day",
                "https://www.midweek.com",
                "https://www.wednesday.com"
            },
            ["Thursday"] = {
                "https://www.thorsday.com",
                "https://www.almostfriday.com",
                "https://www.throwbackthursday.com"
            },
            ["Friday"] = {
                "https://www.tgif.com",
                "https://www.friday.com",
                "https://www.weekend.com"
            },
            ["Saturday"] = {
                "https://www.weekend.com",
                "https://www.saturday.com",
                "https://www.leisure.com"
            }
        }
        
        local ngx_time = ngx.localtime()
        local weekday = os.date("%A", os.time{year=tonumber(string.sub(ngx_time, 1, 4)),
                                               month=tonumber(string.sub(ngx_time, 6, 7)),
                                               day=tonumber(string.sub(ngx_time, 9, 10))})
        
        local sites = days[weekday] or {"https://www.google.com"}
        return sites[math.random(#sites)]
    }
    
    return 301 $target;
}
```

## 3. **地理位置跳转**

### 3.1 使用 IP 地理位置数据库
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    # 需要安装 geoip 模块
    geoip_country /usr/share/GeoIP/GeoIP.dat;
    geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
    
    set_by_lua_block $target {
        local country = ngx.var.geoip_country_code
        local city = ngx.var.geoip_city
        
        -- 根据国家跳转到当地热门网站
        local country_sites = {
            ["CN"] = {
                "https://www.baidu.com",
                "https://www.taobao.com",
                "https://www.jd.com",
                "https://www.qq.com",
                "https://www.bilibili.com"
            },
            ["US"] = {
                "https://www.google.com",
                "https://www.amazon.com",
                "https://www.facebook.com",
                "https://www.youtube.com",
                "https://www.reddit.com"
            },
            ["JP"] = {
                "https://www.yahoo.co.jp",
                "https://www.amazon.co.jp",
                "https://www.rakuten.co.jp",
                "https://www.nicovideo.jp"
            },
            ["KR"] = {
                "https://www.naver.com",
                "https://www.daum.net",
                "https://www.kakao.com",
                "https://www.nate.com"
            },
            ["RU"] = {
                "https://yandex.ru",
                "https://mail.ru",
                "https://vk.com",
                "https://ok.ru"
            }
        }
        
        local sites = country_sites[country]
        if sites then
            return sites[math.random(#sites)]
        else
            -- 默认国际网站
            local defaults = {
                "https://www.wikipedia.org",
                "https://www.github.com",
                "https://www.stackoverflow.com",
                "https://www.bbc.com/news"
            }
            return defaults[math.random(#defaults)]
        end
    }
    
    return 301 $target;
}
```

## 4. **渐进式跳转（连环跳）**

### 4.1 固定次数的渐进跳转
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    # 使用 Cookie 记录跳转次数
    set_by_lua_block $target {
        local cookie = ngx.var.http_cookie or ""
        local jump_count = 0
        
        -- 从 Cookie 中提取跳转次数
        if string.find(cookie, "jump_count=") then
            jump_count = tonumber(string.match(cookie, "jump_count=(%d+)")) or 0
        end
        
        -- 跳转链
        local jump_chain = {
            [0] = "https://jump1.example.com",  -- 第一次跳转
            [1] = "https://jump2.example.com",  -- 第二次跳转
            [2] = "https://jump3.example.com",  -- 第三次跳转
            [3] = "https://final-destination.com"  -- 最终目的地
        }
        
        local next_target = jump_chain[jump_count] or "https://final-destination.com"
        local next_count = math.min(jump_count + 1, 3)
        
        -- 设置 Cookie，增加跳转次数
        ngx.header["Set-Cookie"] = "jump_count=" .. next_count .. "; path=/; max-age=300"
        
        -- 如果是最终目的地，清除 Cookie
        if next_count == 3 then
            ngx.header["Set-Cookie"] = "jump_count=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"
        end
        
        return next_target
    }
    
    return 301 $target;
}
```

### 4.2 随机路径的渐进跳转
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    set_by_lua_block $target {
        local cookie = ngx.var.http_cookie or ""
        local jump_path = ""
        
        -- 可能的跳转路径
        local path_options = {
            {
                "https://start.example.com",
                "https://middle.example.com", 
                "https://end.example.com"
            },
            {
                "https://portal1.example.com",
                "https://gateway.example.com",
                "https://hub.example.com",
                "https://destination.example.com"
            },
            {
                "https://level1.example.com",
                "https://level2.example.com",
                "https://boss.example.com",
                "https://victory.example.com"
            }
        }
        
        -- 如果第一次访问，随机选择一条路径
        if not string.find(cookie, "jump_path=") then
            local path_idx = math.random(#path_options)
            local current_step = 0
            jump_path = path_idx .. ":" .. current_step .. ":" .. table.concat(path_options[path_idx], ",")
            ngx.header["Set-Cookie"] = "jump_path=" .. jump_path .. "; path=/; max-age=600"
            return path_options[path_idx][1]
        else
            -- 解析路径信息
            local path_data = string.match(cookie, "jump_path=([^;]+)")
            local path_idx, current_step, path_str = string.match(path_data, "(%d+):(%d+):(.+)")
            path_idx = tonumber(path_idx)
            current_step = tonumber(current_step)
            
            local path = {}
            for site in string.gmatch(path_str, "([^,]+)") do
                table.insert(path, site)
            end
            
            if current_step < #path then
                current_step = current_step + 1
                local next_target = path[current_step]
                jump_path = path_idx .. ":" .. current_step .. ":" .. path_str
                ngx.header["Set-Cookie"] = "jump_path=" .. jump_path .. "; path=/; max-age=600"
                
                -- 如果是最后一步，添加特效链接
                if current_step == #path then
                    ngx.header["X-Final-Destination"] = "true"
                end
                
                return next_target
            else
                -- 已经到达终点
                ngx.header["Set-Cookie"] = "jump_path=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"
                return path[#path]
            end
        end
    }
    
    return 301 $target;
}
```

## 5. **主题随机跳转**

### 5.1 基于请求路径的主题跳转
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    location ~ "^/([a-z]+)" {
        set_by_lua_block $target {
            local theme = ngx.var[1] or "general"
            
            local themes = {
                tech = {
                    "https://github.com",
                    "https://stackoverflow.com",
                    "https://news.ycombinator.com",
                    "https://dev.to",
                    "https://medium.com/tag/technology"
                },
                art = {
                    "https://www.deviantart.com",
                    "https://www.behance.net",
                    "https://dribbble.com",
                    "https://www.artsy.net",
                    "https://www.pinterest.com"
                },
                music = {
                    "https://www.spotify.com",
                    "https://music.youtube.com",
                    "https://soundcloud.com",
                    "https://www.bandcamp.com",
                    "https://www.last.fm"
                },
                game = {
                    "https://store.steampowered.com",
                    "https://www.epicgames.com",
                    "https://www.twitch.tv",
                    "https://www.reddit.com/r/gaming",
                    "https://www.ign.com"
                },
                science = {
                    "https://www.nasa.gov",
                    "https://www.nature.com",
                    "https://www.sciencemag.org",
                    "https://arxiv.org",
                    "https://www.sciencedaily.com"
                }
            }
            
            local sites = themes[theme] or {
                "https://www.google.com",
                "https://www.wikipedia.org",
                "https://www.reddit.com/r/all",
                "https://www.youtube.com"
            }
            
            return sites[math.random(#sites)]
        }
        
        return 301 $target;
    }
    
    # 默认随机跳转
    location / {
        set_by_lua_block $target {
            local general_sites = {
                "https://www.google.com",
                "https://www.youtube.com",
                "https://www.reddit.com",
                "https://www.wikipedia.org",
                "https://www.github.com",
                "https://www.twitter.com",
                "https://www.netflix.com",
                "https://www.amazon.com"
            }
            return general_sites[math.random(#general_sites)]
        }
        
        return 301 $target;
    }
}
```

## 6. **高级随机跳转（多种算法）**

### 6.1 加权随机跳转
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    set_by_lua_block $target {
        -- 网站及其权重（权重越高，跳转概率越大）
        local weighted_sites = {
            {site = "https://www.google.com", weight = 10},
            {site = "https://www.github.com", weight = 8},
            {site = "https://stackoverflow.com", weight = 7},
            {site = "https://www.youtube.com", weight = 9},
            {site = "https://www.wikipedia.org", weight = 6},
            {site = "https://www.reddit.com", weight = 5},
            {site = "https://news.ycombinator.com", weight = 4},
            {site = "https://www.bilibili.com", weight = 3},
            {site = "https://www.zhihu.com", weight = 2},
            {site = "https://www.taobao.com", weight = 1}
        }
        
        -- 计算总权重
        local total_weight = 0
        for _, item in ipairs(weighted_sites) do
            total_weight = total_weight + item.weight
        end
        
        -- 生成随机数
        math.randomseed(ngx.time() + ngx.worker.pid())
        local random_value = math.random(total_weight)
        
        -- 根据权重选择
        local cumulative = 0
        for _, item in ipairs(weighted_sites) do
            cumulative = cumulative + item.weight
            if random_value <= cumulative then
                return item.site
            end
        end
        
        return weighted_sites[1].site  -- 默认第一个
    }
    
    return 301 $target;
}
```

### 6.2 基于哈希的确定性随机（同一用户相同目标）
```nginx
server {
    listen 80;
    server_name random.shumengya.top;
    
    set_by_lua_block $target {
        -- 可用网站列表
        local sites = {
            "https://www.google.com",
            "https://www.github.com",
            "https://stackoverflow.com",
            "https://www.youtube.com",
            "https://www.wikipedia.org",
            "https://www.reddit.com",
            "https://news.ycombinator.com",
            "https://www.bilibili.com"
        }
        
        -- 获取用户IP或User-Agent作为种子
        local user_ip = ngx.var.remote_addr or "0.0.0.0"
        local user_agent = ngx.var.http_user_agent or ""
        
        -- 创建种子值
        local seed = 0
        for i = 1, #user_ip do
            seed = seed + string.byte(user_ip, i) * i
        end
        for i = 1, math.min(10, #user_agent) do
            seed = seed + string.byte(user_agent, i) * i
        end
        
        -- 使用种子选择网站（同一用户总是得到相同结果）
        math.randomseed(seed)
        local site_index = math.random(#sites)
        
        -- 可选：根据日期变化（每天不同）
        local today = os.date("%Y%m%d")
        local day_seed = 0
        for i = 1, #today do
            day_seed = day_seed + string.byte(today, i) * i
        end
        math.randomseed(seed + day_seed)
        site_index = math.random(#sites)
        
        return sites[site_index]
    }
    
    return 301 $target;
}
```

## 7. **完整部署脚本**

```bash
#!/bin/bash
# deploy-random-redirect.sh

echo "部署 random.shumengya.top 随机跳转服务..."

# 1. 安装 OpenResty（如果需要）
if ! command -v openresty &> /dev/null; then
    echo "安装 OpenResty..."
    # Ubuntu/Debian
    sudo apt-get update
    sudo apt-get install -y software-properties-common
    sudo add-apt-repository -y ppa:openresty/ppa
    sudo apt-get update
    sudo apt-get install -y openresty
    
    # CentOS/RHEL
    # sudo yum install yum-utils
    # sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
    # sudo yum install -y openresty
fi

# 2. 创建配置文件目录
sudo mkdir -p /usr/local/openresty/nginx/conf/conf.d
sudo mkdir -p /usr/local/openresty/nginx/logs

# 3. 创建主配置文件
sudo tee /usr/local/openresty/nginx/conf/nginx.conf > /dev/null << 'EOF'
worker_processes auto;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    include conf.d/*.conf;
}
EOF

# 4. 选择并创建随机跳转配置
echo "请选择跳转类型："
echo "1) 基础随机跳转"
echo "2) 时间条件跳转"
echo "3) 地理位置跳转"
echo "4) 渐进式跳转"
echo "5) 主题随机跳转"
read -p "输入选择 (1-5): " choice

case $choice in
    1)
        CONFIG_FILE="basic-random.conf"
        ;;
    2)
        CONFIG_FILE="time-based.conf"
        ;;
    3)
        CONFIG_FILE="geo-based.conf"
        ;;
    4)
        CONFIG_FILE="progressive.conf"
        ;;
    5)
        CONFIG_FILE="theme-based.conf"
        ;;
    *)
        CONFIG_FILE="basic-random.conf"
        ;;
esac

# 5. 创建选定的配置
sudo tee /usr/local/openresty/nginx/conf/conf.d/random-redirect.conf > /dev/null << 'EOF'
server {
    listen 80;
    server_name random.shumengya.top;
    
    # 这里替换为上面相应的配置内容
    # 为了简洁，这里放置基础随机跳转配置
    set_by_lua_block $random_target {
        local targets = {
            "https://www.google.com",
            "https://github.com",
            "https://stackoverflow.com",
            "https://news.ycombinator.com",
            "https://www.wikipedia.org",
            "https://www.youtube.com",
            "https://twitter.com",
            "https://www.reddit.com"
        }
        math.randomseed(ngx.time() + ngx.worker.pid())
        local idx = math.random(#targets)
        return targets[idx]
    }
    
    return 301 $random_target;
}
EOF

# 6. 启动服务
echo "启动 OpenResty..."
sudo openresty -p /usr/local/openresty/nginx -c conf/nginx.conf

# 7. 创建测试脚本
tee test-random.sh > /dev/null << 'EOF'
#!/bin/bash
echo "测试随机跳转..."
for i in {1..5}; do
    echo "测试 $i:"
    curl -I http://random.shumengya.top 2>/dev/null | grep -i "location:"
    sleep 1
done
EOF

chmod +x test-random.sh

echo "部署完成！"
echo "测试命令: ./test-random.sh"
echo "查看日志: sudo tail -f /usr/local/openresty/nginx/logs/error.log"
```

## 8. **监控和统计**

```nginx
# 添加访问统计
server {
    listen 80;
    server_name random.shumengya.top;
    
    # 记录跳转日志
    log_format random_log '$remote_addr - $remote_user [$time_local] '
                         '"$request" $status $body_bytes_sent '
                         '"$http_referer" "$http_user_agent" '
                         '"$sent_http_location"';
    
    access_log /var/log/nginx/random-access.log random_log;
    
    # Lua 共享内存统计
    lua_shared_dict jump_stats 10m;
    
    set_by_lua_block $target {
        local targets = {
            "https://www.google.com",
            "https://github.com",
            "https://stackoverflow.com",
            "https://www.youtube.com"
        }
        
        math.randomseed(ngx.time() + ngx.worker.pid())
        local idx = math.random(#targets)
        local selected = targets[idx]
        
        -- 统计
        local stats = ngx.shared.jump_stats
        local count = stats:get(selected) or 0
        stats:set(selected, count + 1)
        
        -- 添加响应头显示统计
        ngx.header["X-Total-Jumps"] = stats:get("total") or 0
        ngx.header["X-Site-Stats"] = selected .. ": " .. (count + 1)
        
        return selected
    }
    
    return 301 $target;
    
    # 统计查询接口
    location /stats {
        content_by_lua_block {
            local stats = ngx.shared.jump_stats
            ngx.say("Random Jump Statistics:<br><br>")
            for i = 1, 4 do
                local sites = {"https://www.google.com", "https://github.com", 
                               "https://stackoverflow.com", "https://www.youtube.com"}
                local count = stats:get(sites[i]) or 0
                ngx.say(sites[i] .. ": " .. count .. " jumps<br>")
            end
        }
    }
}
```

## 9. **安全注意事项**

```nginx
# 防止滥用的配置
server {
    listen 80;
    server_name random.shumengya.top;
    
    # 限制请求频率
    limit_req_zone $binary_remote_addr zone=random_limit:10m rate=10r/s;
    
    location / {
        limit_req zone=random_limit burst=20;
        
        # 防止爬虫滥用
        if ($http_user_agent ~* (bot|crawler|spider|scraper|curl|wget)) {
            # 给爬虫返回固定的目标，避免随机性
            return 301 https://www.example.com/robots-friendly-page;
        }
        
        set_by_lua_block $target {
            -- 正常的随机跳转逻辑
            -- ...
        }
        
        return 301 $target;
    }
}
```

## 10. **创意想法扩展**

1. **教育模式**：跳转到随机教育网站（可汗学院、Coursera等）
2. **开发者模式**：只跳转到技术文档和API网站
3. **冒险模式**：跳转到奇怪的、小众的网站
4. **怀旧模式**：跳转到复古风格的网站
5. **彩蛋模式**：特定日期或特定IP跳转到特殊网站

选择最适合你需求的方案，每个都可以根据你的具体需求进行调整和扩展！