Hugo博客公告弹窗

OpenLiteSpeed 访问ip跳转404

   
文章摘要
摘要小助理今天溜号啦……😜

修改 OpenLiteSpeed 的配置

找到配置文件路径:例如我的ip是2.2.2.2

cd /usr/local/lsws/conf/vhosts/2.2.2.2/

编辑vhost.conf文件,

nano vhost.conf

写入如下内容:

# 虚拟主机配置

docRoot                   $VH_ROOT/public_html
vhDomain                  $VH_NAME
vhAliases                 www.$VH_NAME
adminEmails               $VH_ADMIN_EMAIL
enableGzip                1
enableIpGeo               1

# 重写规则
rewrite  {
  enable                  1
  rules                   <<<END_RULES
  # 检查是否是通过 IP 地址访问
  RewriteCond %{HTTP_HOST} ^[0-9.]+$
  # 如果是 IP 访问,重定向到 404 页面
  RewriteRule ^ /404.html [L]
  END_RULES
}

# 错误页面配置
errordoc 404 {
  url                     /404.html
}

新建404页面

cd /home/2.2.2.2/public_html/  #回到ip目录
touch 404.html

写入内容:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>404 - 页面未找到</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            color: #333;
        }
        .container {
            text-align: center;
            background-color: white;
            padding: 2rem;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            max-width: 80%;
        }
        h1 {
            font-size: 4rem;
            margin-bottom: 0;
            color: #e74c3c;
        }
        p {
            font-size: 1.2rem;
            margin-top: 1rem;
        }
        #countdown {
            font-size: 2rem;
            font-weight: bold;
            color: #3498db;
            margin: 1rem 0;
        }
        .cat-icon {
            font-size: 5rem;
            margin-bottom: 1rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="cat-icon">🐱</div>
        <h1>404</h1>
        <p>哎呀!看来您迷路了。</p>
        <p>别担心,我们正在带您回家。</p>
        <div id="countdown">5</div>
        <p>秒后返回 catpdf.org</p>
    </div>

    <script>
        let count = 5;
        const countdownElement = document.getElementById('countdown');
        
        const countdownTimer = setInterval(() => {
            count--;
            countdownElement.textContent = count;
            
            if (count <= 0) {
                clearInterval(countdownTimer);
                window.location.href = 'https://xxx.org';
            }
        }, 1000);
    </script>
</body>
</html>

重启服务:

systemctl restart lsws

搞定!


CC BY-NC-SA 4.0 转载请注明
最后更新于 2024-11-23 15:12
clarity统计