360 Secure SkillHub
360 安全技能中心

Hostinger Deploy

该 Skill 将本地 dist/ 中已构建的静态站点或 SPA 通过 rsync over SSH 增量推送到 Hostinger 共享主机,自动注入或更新 .htaccess 以支持前端路由,并提供跳过构建、dry-run 与回滚方式,另附可选的 GitHub Actions 自动部署示例。

codaire
codaire
热度 21.97
最近更新 2026-04-02 02:41:46
分类:开发依赖:代码执行 / 读写文件应用场景:DevOps / 自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add hostinger-deploy
Metadata
name
hostinger-deploy
description
One-command deployment from a local React/Vite dist folder to Hostinger shared hosting via rsync + SSH. Handles SPA routing (.htaccess), incremental pushes, and rollback. Use when deploying a static site or SPA to Hostinger shared hosting, or when setting up a deployment pipeline for the first time.

Hostinger Deploy Skill

One-command deployment from a local dist/ folder to Hostinger shared hosting via rsync over SSH. Handles SPA routing, incremental pushes, and rollback. Works with React, Vite, Next.js (static export), Astro, or any static/SPA build.

What It Does

  • Runs npm run build locally
  • Rsyncs dist/ to Hostinger web root (incremental, skips unchanged files)
  • Injects/updates .htaccess for SPA routing (RewriteRule . /index.html [L])
  • Works with any React/Vite/Next.js/Astro static export
  • Single config section at the top of the script

Prerequisites

  • rsync installed locally (brew install rsync / apt install rsync)
  • SSH key access to your Hostinger account
  • Your site builds to a dist/ directory

Setup

1. Add SSH key to Hostinger

In Hostinger hPanel → SSH Access → Add your public key:

cat ~/.ssh/id_ed25519.pub
# or
cat ~/.ssh/id_rsa.pub

If you don't have an SSH key yet:

ssh-keygen -t ed25519 -C "your_email@example.com"

2. Configure the script

Edit the top config section of scripts/deploy.sh:

HOST="u528135200@your-username.your-domain.com"   # SSH host (username@domain)
PORT="22"                                          # SSH port (22 = standard, 65002 = some Hostinger accounts)
DEST="/home/username/domains/your-domain.com/public_html"  # Hostinger web root
DIST="dist"                                        # Your build output directory

Finding your web root: In Hostinger hPanel → Website → Details → Primary Domain → shows the path.

Finding your SSH port: Some Hostinger accounts use port 22, others a custom port (e.g., 65002). Check your SSH details in hPanel.

3. Test the connection

ssh -p 65002 u528135200@your-hostname.com "echo 'SSH OK'"

4. Run first deploy

bash deploy.sh
# Output:
# === Building ===
# === Rsyncing to Hostinger ===
# === Adding SPA routing rule ===
# === Live at https://your-domain.com ===

Deployment Commands

# Standard deploy (build + push)
bash deploy.sh

# Push only (skip build — if dist/ is already built locally)
bash deploy.sh --no-build

# Dry run (see what would be pushed, no changes made)
rsync -avzn -e "ssh -p 65002" dist/ u528135200@host:/home/username/domains/example.com/public_html/

# Rollback: restore a previous deploy
# Hostinger keeps previous versions in hPanel → Backups → Website Backups
# Or use rsync in reverse:
rsync -avz -e "ssh -p 65002" \
  --delete \
  u528135200@host:/home/username/domains/example.com/public_html/ \
  dist-rollback/

SPA Routing (.htaccess)

The script automatically injects this .htaccess if missing or updates it:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

This routes all 404s to index.html, enabling client-side routing for React Router, Vue Router, etc.


GitHub Actions CI/CD (Optional)

Add automatic deploys on every push to main:

# .github/workflows/deploy.yml
name: Deploy to Hostinger

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install & Build
        run: |
          npm ci
          npm run build

      - name: Deploy to Hostinger
        env:
          HOST: ${{ secrets.HOSTINGER_HOST }}
          PORT: ${{ secrets.HOSTINGER_PORT }}
          DEST: ${{ secrets.HOSTINGER_DEST }}
        run: |
          chmod +x deploy.sh
          ./deploy.sh
        # Note: deploy.sh should use SSH key authentication
        # Add private key via secrets.HOSTINGER_SSH_KEY

Add secrets to your GitHub repo: Settings → Secrets → Actions:

  • HOSTINGER_HOST — u528135200@your-domain.com
  • HOSTINGER_PORT — 22 or 65002
  • HOSTINGER_DEST — /home/username/domains/your-domain.com/public_html
  • HOSTINGER_SSH_KEY — your private SSH key (base64 encoded or use actions/checkout with deploy key)

One-Command Push (without build)

If dist/ is already up-to-date locally and you just want to push:

rsync -avz --delete \
  -e "ssh -p 65002" \
  --exclude '.htaccess' \
  dist/ \
  u528135200@host:/home/username/domains/example.com/public_html/

Files

  • scripts/deploy.sh — the deploy script (edit the config section at the top)
  • docs/config.md — step-by-step setup guide with Hostinger-specific instructions