🚧 网站建设中,内容持续完善中 🚧
01MVP

EdgeOne 速查表

腾讯 EdgeOne 常用命令和配置速查手册

EdgeOne 速查表

🚀 快速开始

基本信息

核心数据

  • 全球节点:3200+ 个 CDN POP
  • 亚洲节点:2500+ 个(亚洲优化)
  • 全球带宽:200 Tbps
  • CDN 功能:100+ 种自定义能力
  • 加速类型:L4/L7 智能加速

📁 项目配置

edgeone.yml 配置文件

# 基础配置
name: my-project
version: 1.0.0

# 构建配置
build:
  command: npm run build
  output: dist
  node_version: 18

# 路由配置
routes:
  # SPA 路由
  - src: "/(.*)"
    dest: "/index.html"
  
  # API 代理
  - src: "/api/(.*)"
    dest: "https://api.example.com/$1"
  
  # 静态资源缓存
  - src: "/static/(.*)"
    headers:
      Cache-Control: "public, max-age=31536000, immutable"

# 环境变量
env:
  NODE_ENV: production
  API_URL: https://api.example.com

# 自定义头部
headers:
  - src: "/(.*)"
    headers:
      X-Frame-Options: DENY
      X-Content-Type-Options: nosniff

Next.js 优化配置

// next.config.js
module.exports = {
  // 静态导出
  output: 'export',
  trailingSlash: true,
  
  // 图片优化
  images: {
    unoptimized: true,
    domains: ['cdn.example.com']
  },
  
  // CDN 配置
  assetPrefix: process.env.NODE_ENV === 'production' 
    ? 'https://cdn.example.com' 
    : '',
  
  // 缓存优化
  headers: async () => [
    {
      source: '/static/(.*)',
      headers: [
        {
          key: 'Cache-Control',
          value: 'public, max-age=31536000, immutable'
        }
      ]
    }
  ]
}

🛠️ CLI 命令

安装和登录

# 安装 CLI
npm install -g @edgeone/cli

# 登录
edgeone login

# 查看版本
edgeone --version

项目管理

# 初始化项目
edgeone init

# 部署项目
edgeone deploy

# 预览部署
edgeone deploy --preview

# 查看部署状态
edgeone status

# 查看部署日志
edgeone logs

# 删除部署
edgeone remove

域名管理

# 添加自定义域名
edgeone domain add example.com

# 查看域名列表
edgeone domain list

# 删除域名
edgeone domain remove example.com

# 查看域名状态
edgeone domain status example.com

环境变量

# 设置环境变量
edgeone env set API_URL=https://api.example.com

# 查看环境变量
edgeone env list

# 删除环境变量
edgeone env remove API_URL

# 从文件导入
edgeone env import .env

🌐 域名和 SSL

DNS 配置

# CNAME 记录(推荐)
www.example.com  CNAME  xxx.edgeone.ai

# A 记录
example.com      A      1.2.3.4

# AAAA 记录(IPv6)
example.com      AAAA   2001:db8::1

SSL 证书

# 自动 SSL(推荐)
ssl:
  auto: true
  force_https: true

# 自定义证书
ssl:
  cert: |
    -----BEGIN CERTIFICATE-----
    ...
    -----END CERTIFICATE-----
  key: |
    -----BEGIN PRIVATE KEY-----
    ...
    -----END PRIVATE KEY-----

⚡ 性能优化

缓存策略

# 静态资源长期缓存
routes:
  - src: "\.(js|css|png|jpg|jpeg|gif|svg|woff|woff2)$"
    headers:
      Cache-Control: "public, max-age=31536000, immutable"
  
  # HTML 短期缓存
  - src: "\.html$"
    headers:
      Cache-Control: "public, max-age=3600"
  
  # API 不缓存
  - src: "/api/.*"
    headers:
      Cache-Control: "no-cache, no-store, must-revalidate"

压缩配置

# Gzip 压缩
compression:
  gzip: true
  brotli: true
  types:
    - text/html
    - text/css
    - text/javascript
    - application/javascript
    - application/json

图片优化

# 图片处理
image_optimization:
  enabled: true
  formats: [webp, avif]
  quality: 80
  sizes: [640, 750, 828, 1080, 1200]

🔒 安全配置

安全头部

headers:
  - src: "/(.*)"
    headers:
      # 防止点击劫持
      X-Frame-Options: DENY
      
      # 防止 MIME 类型嗅探
      X-Content-Type-Options: nosniff
      
      # XSS 保护
      X-XSS-Protection: "1; mode=block"
      
      # 引用策略
      Referrer-Policy: "strict-origin-when-cross-origin"
      
      # 内容安全策略
      Content-Security-Policy: "default-src 'self'; script-src 'self' 'unsafe-inline'"

DDoS 防护

# DDoS 防护配置
security:
  ddos_protection:
    enabled: true
    sensitivity: medium
  
  # 速率限制
  rate_limiting:
    enabled: true
    requests_per_minute: 100
    burst: 200

WAF 规则

# Web 应用防火墙
waf:
  enabled: true
  rules:
    - name: "Block SQL Injection"
      pattern: "(union|select|insert|delete|update|drop)"
      action: block
    
    - name: "Block XSS"
      pattern: "<script|javascript:|on\w+="
      action: block

📊 监控和分析

性能监控

// 性能监控代码
if (typeof window !== 'undefined') {
  // 页面加载时间
  window.addEventListener('load', () => {
    const loadTime = performance.timing.loadEventEnd - performance.timing.navigationStart
    console.log('Page load time:', loadTime + 'ms')
  })
  
  // Core Web Vitals
  import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals'
  
  getCLS(console.log)
  getFID(console.log)
  getFCP(console.log)
  getLCP(console.log)
  getTTFB(console.log)
}

错误监控

// 全局错误捕获
window.addEventListener('error', (event) => {
  const errorData = {
    message: event.message,
    filename: event.filename,
    lineno: event.lineno,
    colno: event.colno,
    error: event.error?.stack
  }
  
  // 发送到监控服务
  fetch('/api/errors', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(errorData)
  })
})

🔧 常用代码片段

环境检测

// 检测是否在 EdgeOne 环境
const isEdgeOne = process.env.EDGEONE_REGION !== undefined

// 获取部署信息
const deployInfo = {
  region: process.env.EDGEONE_REGION,
  version: process.env.EDGEONE_VERSION,
  url: process.env.EDGEONE_URL
}

地理位置获取

// 获取用户地理位置(EdgeOne 提供)
const getGeoInfo = (req) => {
  return {
    country: req.headers['cf-ipcountry'],
    region: req.headers['cf-region'],
    city: req.headers['cf-city'],
    ip: req.headers['cf-connecting-ip']
  }
}

A/B 测试

// 基于地理位置的 A/B 测试
const getVariant = (country) => {
  const variants = {
    'CN': 'variant-china',
    'US': 'variant-us',
    'default': 'variant-global'
  }
  
  return variants[country] || variants.default
}

🐛 故障排查

常见问题

问题原因解决方案
部署失败构建命令错误检查 build.command 配置
404 错误路由配置错误检查 routes 配置
SSL 证书问题域名验证失败检查 DNS 配置
缓存问题缓存策略错误检查 Cache-Control 头部
性能问题资源未优化启用压缩和图片优化

调试命令

# 查看详细日志
edgeone logs --verbose

# 测试配置
edgeone config validate

# 清除缓存
edgeone cache clear

# 健康检查
edgeone health

性能分析

# 分析包大小
npx webpack-bundle-analyzer dist

# 检查 Core Web Vitals
npx lighthouse https://your-site.com

# 测试加载速度
curl -w "@curl-format.txt" -o /dev/null -s https://your-site.com

📚 有用链接


提示:EdgeOne 功能持续更新,建议定期查看官方文档获取最新信息。

On this page