mcpField
H
hosting

hosting

github.com/hostinger云与 DevOps26109 次安装19 周前更新
代码仓库

关于 hosting

hosting 介绍用于管理共享主机资源的 Hostinger Hosting API,适合自动化网站运维的开发者。内容涵盖网站创建,以及数据库、域名、Node.js 部署和 WordPress 安装。

主要功能

  1. 01创建和查询网站及订单
  2. 02选择数据中心并验证域名
  3. 03生成免费子域名
  4. 04管理数据库与网站域名
  5. 05从归档构建 Node.js 应用
  6. 06安装并查询 WordPress

适用场景

  1. 01创建托管网站
  2. 02管理数据库和网站域名
  3. 03部署 Node.js 项目归档
  4. 04在现有网站安装 WordPress

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hostinger/hostinger-agent-skills --skill hosting

安装后在 Claude Code 中输入/hosting确认已加载。

详细介绍

Hostinger 主机

Hosting API 管理共享主机服务——创建网站、列出订单、选择数据中心、验证域名所有权、生成免费子域名、管理数据库、子域名和停靠域名、部署 Node.js 应用,以及安装 WordPress。

目录

核心概念

网站

网站是核心主机资源。每个网站都与一个域名和一个主机订单关联。网站类型包括主网站和附加网站。创建网站时,如果它是该方案上的第一个网站,则会触发主机账户开通。

订单

主机订单代表已购买的主机方案。订单可以按状态和 ID 进行筛选。支持共享访问——你可以查看已授予你访问权限的其他账户的订单。

数据中心

在新的主机方案上创建第一个网站时,你必须选择一个数据中心。数据中心列表中的第一项最符合你的订单需求。后续网站会自动使用相同的数据中心。

域名验证

在将域名用于主机之前,必须验证所有权。Hostinger 免费子域名(*.hostingersite.com)跳过验证。对于其他域名,请将提供的 TXT 记录添加到你的 DNS 并进行验证。传播最多可能需要 10 分钟。

免费子域名

Hostinger 在 *.hostingersite.com 下提供免费子域名,无需购买自定义域名即可立即使用。

主机账户(username)

除了上述订单/网站模型之外,许多主机操作都限定在主机账户范围内,由其 username 标识。该用户名会在网站列表中返回(GET /api/hosting/v1/websites),并且是管理数据库、子域名、停靠域名、Node.js 构建以及按账户的 WordPress 安装(/api/hosting/v1/accounts/{username}/...)的路径根。数据库名称和用户会自动添加该用户名作为前缀。

数据库

每个主机账户可以容纳多个 MySQL 数据库,每个数据库都有自己的数据库用户和密码。数据库会分配给一个网站域名。你可以创建和删除数据库、更改数据库用户密码、修复损坏的表,以及获取用于可视化管理的一次性登录 phpMyAdmin 链接。

子域名和停靠域名
  • 子域名——现有网站下的附加主机名(例如 blog.example.com),每个都有自己的文档根目录。
  • 停靠域名(别名域名)——提供与父网站相同内容的附加域名。

两者都在特定网站下进行管理:/api/hosting/v1/accounts/{username}/websites/{domain}/...。

Node.js 应用

支持 Node.js 的方案上的网站会运行构建流水线。推荐流程会一步上传项目归档、根据其 package.json 自动检测构建设置并启动构建。每个构建都有一个 uuid 和一个状态(pending、running、completed、failed);轮询构建日志(使用 from_line)以在构建运行时流式输出。

WordPress

在现有网站上安装 WordPress。网站必须已经存在——先通过 POST /api/hosting/v1/websites 创建它,并轮询直到它出现。安装是异步的;轮询 GET /api/hosting/v1/wordpress/installations 以确认就绪。

常见模式

创建网站(完整流程)
# Step 1: List available datacenters for your order
curl -X GET "https://developers.hostinger.com/api/hosting/v1/datacenters?order_id=12345" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Step 2: Generate a free subdomain (optional, if no custom domain)
curl -X POST "https://developers.hostinger.com/api/hosting/v1/domains/free-subdomains" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Step 3: Verify domain ownership (skip for *.hostingersite.com)
curl -X POST "https://developers.hostinger.com/api/hosting/v1/domains/verify-ownership" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "domain": "example.com" }'

# Step 4: Create the website
curl -X POST "https://developers.hostinger.com/api/hosting/v1/websites" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "example.com",
    "order_id": 12345,
    "datacenter_code": "us-east-1"
  }'

Python SDK:

from hostinger_api import Hostinger

client = Hostinger(api_token="YOUR_API_TOKEN")

# List datacenters
datacenters = client.hosting.datacenters.list(order_id=12345)
dc_code = datacenters[0].code  # Use recommended datacenter

# Create website
client.hosting.websites.create(
    domain="example.com",
    order_id=12345,
    datacenter_code=dc_code
)

TypeScript SDK:

import { Hostinger } from "hostinger-api-sdk";

const client = new Hostinger({ apiToken: "YOUR_API_TOKEN" });

const datacenters = await client.hosting.datacenters.list({ orderId: 12345 });
const dcCode = datacenters[0].code;

await client.hosting.websites.create({
  domain: "example.com",
  orderId: 12345,
  datacenterCode: dcCode,
});

PHP SDK:

use Hostinger\Api\HostingerApi;

$client = new HostingerApi('YOUR_API_TOKEN');

$datacenters = $client->hosting->datacenters->list(['order_id' => 12345]);
$dcCode = $datacenters[0]->code;

$client->hosting->websites->create([
    'domain' => 'example.com',
    'order_id' => 12345,
    'datacenter_code' => $dcCode,
]);
列出网站
# List all websites
curl -X GET "https://developers.hostinger.com/api/hosting/v1/websites" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Filter by order ID
curl -X GET "https://developers.hostinger.com/api/hosting/v1/websites?order_id=12345" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Filter by domain
curl -X GET "https://developers.hostinger.com/api/hosting/v1/websites?domain=example.com" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Paginate results
curl -X GET "https://developers.hostinger.com/api/hosting/v1/websites?page=2&per_page=25" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"
列出主机订单
# List all orders
curl -X GET "https://developers.hostinger.com/api/hosting/v1/orders" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Filter by status
curl -X GET "https://developers.hostinger.com/api/hosting/v1/orders?statuses=active" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"
管理数据库
# List databases for an account (filter by domain / assignment / search)
curl -X GET "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/databases?domain=example.com&is_assigned=true" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Create a database (name and user are auto-prefixed with the account username)
curl -X POST "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/databases" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "appdb",
    "user": "appuser",
    "password": "SecurePass123!",
    "website_domain": "example.com"
  }'

# Change the database user password (also update it in your site config)
curl -X PATCH "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/databases/u123456789_appdb/change-password" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "password": "NewSecurePass456!" }'

# Get a single sign-on phpMyAdmin link
curl -X GET "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/databases/u123456789_appdb/phpmyadmin-link" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Repair corrupted tables (asynchronous)
curl -X PATCH "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/databases/u123456789_appdb/repair" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Delete a database (use the full name from the list endpoint)
curl -X DELETE "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/databases/u123456789_appdb" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

Python SDK:

from hostinger_api import Hostinger

client = Hostinger(api_token="YOUR_API_TOKEN")

# Create a database
client.hosting.databases.create(
    username="u123456789",
    name="appdb",
    user="appuser",
    password="SecurePass123!",
    website_domain="example.com",
)

# List databases
databases = client.hosting.databases.list(username="u123456789")
for db in databases:
    print(db.name)

TypeScript SDK:

import { Hostinger } from "hostinger-api-sdk";

const client = new Hostinger({ apiToken: "YOUR_API_TOKEN" });

await client.hosting.databases.create("u123456789", {
  name: "appdb",
  user: "appuser",
  password: "SecurePass123!",
  websiteDomain: "example.com",
});

const databases = await client.hosting.databases.list("u123456789");

PHP SDK:

use Hostinger\Api\HostingerApi;

$client = new HostingerApi('YOUR_API_TOKEN');

$client->hosting->databases->create('u123456789', [
    'name' => 'appdb',
    'user' => 'appuser',
    'password' => 'SecurePass123!',
    'website_domain' => 'example.com',
]);

$databases = $client->hosting->databases->list('u123456789');
管理子域名和停靠域名
# List subdomains for a website
curl -X GET "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/subdomains" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Create a subdomain (optionally with a custom directory)
curl -X POST "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/subdomains" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "subdomain": "blog",
    "directory": "blog",
    "is_using_public_directory": false
  }'

# Delete a subdomain
curl -X DELETE "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/subdomains/blog" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# List parked (alias) domains
curl -X GET "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/parked-domains" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Park a domain so it serves the same content as the parent website
curl -X POST "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/parked-domains" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "parked_domain": "example.net" }'

# Remove a parked domain
curl -X DELETE "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/parked-domains/example.net" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"
部署 Node.js 应用
# Create and start a build from a project archive (settings auto-detected from package.json)
curl -X POST "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/nodejs/builds/from-archive" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "archive": "uploads/my-app.zip",
    "node_version": 20,
    "app_type": "ssr",
    "build_script": "build",
    "entry_file": "server.js",
    "package_manager": "npm"
  }'

# List builds (filter by state)
curl -X GET "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/nodejs/builds?states[]=running" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

# Stream build logs while running (poll with from_line = previously returned line count)
curl -X GET "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/websites/example.com/nodejs/builds/3f9a.../logs?from_line=0" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"
安装 WordPress
# Step 1: ensure the website exists (POST /websites, then poll GET /websites)
# Step 2: install WordPress on it
curl -X POST "https://developers.hostinger.com/api/hosting/v1/accounts/u123456789/wordpress/installations" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "example.com",
    "site_title": "My Site",
    "language": "en_US",
    "directory": "public_html",
    "auto_updates": "minor",
    "credentials": {
      "email": "[email protected]",
      "login": "admin",
      "password": "SecureAdminPass123!"
    }
  }'

# Step 3: poll for readiness (installation is asynchronous)
curl -X GET "https://developers.hostinger.com/api/hosting/v1/wordpress/installations?username=u123456789&domain=example.com" \
  -H "Authorization: Bearer $HOSTINGER_API_TOKEN"

API 参考

数据中心
方法端点描述
GET/api/hosting/v1/datacenters列出可用数据中心(需要 order_id 查询参数)
域名
方法端点描述
POST/api/hosting/v1/domains/free-subdomains生成免费子域名
POST/api/hosting/v1/domains/verify-ownership验证域名所有权
订单
方法端点描述
GET/api/hosting/v1/orders列出托管订单(分页,可筛选)
网站
方法端点描述
GET/api/hosting/v1/websites列出网站(分页,可筛选)
POST/api/hosting/v1/websites创建新网站
网站查询参数
参数描述
page页码
per_page每页条目数
username按用户名筛选
order_id按订单 ID 筛选
is_enabled按启用状态筛选
domain按域名筛选
数据库
方法端点描述
GET/api/hosting/v1/accounts/{username}/databases列出账户数据库(筛选条件:page、per_page、domain、is_assigned、search)
POST/api/hosting/v1/accounts/{username}/databases创建数据库并设置用户和密码
DELETE/api/hosting/v1/accounts/{username}/databases/{name}删除数据库(使用完整名称)
PATCH/api/hosting/v1/accounts/{username}/databases/{name}/change-password更改数据库用户密码
GET/api/hosting/v1/accounts/{username}/databases/{name}/phpmyadmin-link获取 phpMyAdmin 单点登录链接
PATCH/api/hosting/v1/accounts/{username}/databases/{name}/repair修复损坏的表(异步)
子域名
方法端点描述
GET/api/hosting/v1/accounts/{username}/websites/{domain}/subdomains列出网站子域名
POST/api/hosting/v1/accounts/{username}/websites/{domain}/subdomains创建子域名
DELETE/api/hosting/v1/accounts/{username}/websites/{domain}/subdomains/{subdomain}删除子域名
停放域名
方法端点描述
GET/api/hosting/v1/accounts/{username}/websites/{domain}/parked-domains列出停放(别名)域名
POST/api/hosting/v1/accounts/{username}/websites/{domain}/parked-domains创建停放域名
DELETE/api/hosting/v1/accounts/{username}/websites/{domain}/parked-domains/{parkedDomain}删除停放域名
Node.js
方法端点描述
GET/api/hosting/v1/accounts/{username}/websites/{domain}/nodejs/builds列出构建(筛选条件:page、per_page、states)
POST/api/hosting/v1/accounts/{username}/websites/{domain}/nodejs/builds/from-archive从归档创建并启动构建
GET/api/hosting/v1/accounts/{username}/websites/{domain}/nodejs/builds/{uuid}/logs获取构建日志(使用 from_line 轮询)
WordPress
方法端点描述
POST/api/hosting/v1/accounts/{username}/wordpress/installations在现有网站上安装 WordPress
GET/api/hosting/v1/wordpress/installations列出 WordPress 安装(筛选条件:username、domain、ownership)

最佳实践

网站创建
  • 除非有地理区域要求,否则始终选择推荐的数据中心(列表中的第一个)
  • datacenter_code 仅对新托管方案中的第一个网站是必需的
  • 域名不能以 www. 开头——请使用裸域名
  • 网站创建最多需要几分钟——请轮询列表端点以检查状态
域名验证
  • 跳过 Hostinger 免费子域名(*.hostingersite.com)的验证
  • DNS TXT 记录传播最多可能需要 10 分钟
  • 在尝试创建网站之前先完成验证
免费子域名
  • 使用免费子域名进行测试或快速上手
  • 之后可以连接自定义域名
订单
  • 使用筛选器缩小结果范围,而不是获取全部内容
  • 共享访问订单会与你自己的一同显示
数据库
  • 你提供的 name 和 user 会自动加上账户 username 作为前缀——在调用删除/修改密码/修复/phpMyAdmin 时,请始终使用列表端点返回的完整名称
  • 在 change-password 之后,请更新任何使用该数据库的网站配置(例如 wp-config.php)中的凭据
  • repair 是异步运行的——请重新列出或重试该操作,而不是期望立即得到结果
子域名与停放域名
  • 使用子域名在同一主机下提供不同内容(blog.example.com);使用停放域名从另一个域名提供相同内容
  • 子域名的 DNS 必须指向 Hostinger,主机才能解析
Node.js
  • 优先使用 from-archive 端点——它会在一步内从 package.json 自动检测构建设置
  • 当构建状态为 running 时,使用 from_line(上一次的 lines 计数)轮询日志端点,以仅流式获取新输出
WordPress
  • 目标网站必须在安装之前就已存在——请先创建它并轮询网站列表
  • 安装是异步的;通过轮询 GET /wordpress/installations 确认完成
  • 除非你有理由禁用更新,否则请使用 auto_updates: minor(默认安全选项)

故障排除

网站创建失败
  • 先验证域名所有权(除非使用免费子域名)
  • 确保 order_id 有效且属于一个有效的托管方案
  • 对于第一个网站,datacenter_code 是必需的
  • 域名不能以 www. 开头
域名验证失败
  • TXT 记录可能尚未传播(最多等待 10 分钟)
  • 验证 TXT 记录设置正确:dig TXT example.com
  • 确保你验证的是正确的域名(裸域名,而不是子域名)
数据中心列表为空
  • 确保提供了 order_id 参数且其有效
  • 该订单可能在任何数据中心都没有可用容量
创建后网站未出现
  • 网站配置需要几分钟时间
  • 轮询网站列表端点以检查它何时可用
数据库操作返回 404
  • 使用来自列表端点的完整带前缀的数据库名称(例如 u123456789_appdb),而不是你传给创建操作的短名称
  • 确认路径中的 username 与拥有该数据库的账户匹配
Node.js 构建失败
  • 检查构建日志:GET .../nodejs/builds/{uuid}/logs
  • 确认归档中存在 package.json,并且 build_script/entry_file 正确
  • 确保 node_version 与你的应用所需版本匹配
WordPress 安装未完成
  • 先确认网站存在(GET /websites)——如果网站缺失,安装会失败
  • 安装是异步的——轮询 GET /wordpress/installations(按 username + domain 筛选)
  • 仅当你打算替换目标目录中的现有文件时,才设置 overwrite: true

参考资料

评论

支持 Markdown