Skip to main content

Static Website Hosting

TCB provides developers with static web hosting capabilities, supporting the distribution of static resources such as HTML, CSS, JavaScript, and fonts. Built on Tencent Cloud COS and a global CDN network, it delivers high-performance and high-availability access for your website.

Applicable Scenarios: File-level Operations

The tcb hosting is an operational tool at the file dimension, suitable for the following scenarios:

  • Manually upload / synchronize static files (HTML, CSS, JS, images, fonts, etc.)
  • Pure static content with no build process (e.g., documentation site artifacts, design mockup exported pages)
  • Requires fine-grained control over cloud file paths

If your project has a build step (frontend frameworks like React / Vue / Next.js / Vite / Angular / Nuxt), we recommend using Application Deployment (tcb app deploy), which automatically completes the entire process: install dependencies → build → upload artifacts → bind routes.

Prerequisites

Before using the CLI to operate the static website service, ensure that:

  1. Have a Tencent Cloud account and complete real-name authentication
  2. Go to TCB to create a TCB environment

Deploy Website

Full Deployment

The tcb hosting deploy command deploys all files in the current directory to the static website.

# Go to Build Directory
cd docs

# Deploy all files in the current directory
tcb hosting deploy -e envId

Deploy Specified Files

You can specify specific files or folders for deployment:

# Basic Syntax
tcb hosting deploy <localPath> [cloudPath] -e envId

Parameter Description:

  • localPath: Local file or folder path
  • cloudPath: Cloud target path (Optional, default is the root directory)
  • envId: Environment ID

Example:

# Deploy all files in the hosting directory to the root directory
tcb hosting deploy hosting -e envId

# Deploy the local index.html to the cloud root directory
tcb hosting deploy ./index.html -e envId

# Deploy the index.js in the static directory to static/index.js in the cloud
tcb hosting deploy ./static/index.js static/index.js -e envId

Deployment Limitations

  • File Size: Maximum supported size for a single file is 50TB
  • File Count: Unlimited
  • Network Optimization: If you encounter errors during large-scale file uploads with the error { message: 'socket hang up', code: 'ECONNRESET' }, please first execute:
    export COS_SDK_KEEPALIVE=false

SPA Application Configuration

Vue History Mode

When using Vue Router's history mode, you need to configure the error page as the application's entry page (usually index.html) in the settings page of the Static Website Console.

Website Management

View Service Information

View the status, access domain, and other details of the static website:

tcb hosting detail -e envId

View File List

List all files in the static website storage space:

tcb hosting list -e envId

Delete File

Delete the specified files or folders in the static website:

# Delete Specified Files or Folders
tcb hosting delete <cloudPath> -e envId

# Delete All Files (when cloudPath is empty)
tcb hosting delete -e envId

Command Parameters:

ParameterDescriptionRequired
cloudPathCloud file or folder pathNo (if not specified, delete all files)
-e, --env-id <envId>Environment IDYes
--dirTarget is a folder (recursive deletion)No
--forceForce deletion and skip confirmation promptsNo
--dry-runSimulate the operation to preview files to be deleted without actual executionNo

Example:

# Delete index.html in the root directory
tcb hosting delete index.html -e envId

# Delete the static folder and all its contents
tcb hosting delete static --dir -e envId

# Preview files to be deleted (without actual execution)
tcb hosting delete static --dir --dry-run -e envId

# Empty the entire static website
tcb hosting delete -e envId

# Force Delete, Skip Confirmation
tcb hosting delete static --dir --force -e envId

Path Description

Path Format

  • localPath: Local file or folder path

    • Format: directory/filename
    • Example: ./index.js, static/css/index.css
  • cloudPath: Relative path of the cloud file or folder

    • Format: directory/filename (relative to the root directory)
    • Example: index.js, static/css/index.js

Cross-Platform Precautions

Windows System
  • localPath: Use the system path format, usually with the \ separator
  • cloudPath: Uniformly use the / separator, being independent of the operating system :::

Frequently Asked Questions

Handling Upload Failures

If you encounter upload failures due to network connection issues, you can try:

# Disable SDK Persistent Connections
export COS_SDK_KEEPALIVE=false

# Then re-run the deployment command
tcb hosting deploy -e envId

Domain Access

After deployment is complete, you can access the website via the following methods:

  • View the assigned default domain in the console
  • Configure custom domain (ICP filing required)