白嫖一台主机,难点是开口要码 | Free Hosting; the Hard Part Is Asking Nicely
不用 GitHub、不花一分钱,用一个 Discord 要来的邀请码开通 DomCloud 免费主机,然后用官方部署脚本上线一个带 HTTPS 的静态个人主页,并把 SSH、数据库和网页 VS Code 全部验证一遍。/ With no GitHub and no money, use an invite code from Discord to activate a free DomCloud host, then deploy a static personal homepage with HTTPS using the official deploy script, and verify SSH, the database, and browser-based VS Code along the way.
完整案例:
macOS M2 16G 在这里只负责浏览器和一个终端窗口,网站跑在对方机房。Your M2 with 16GB only supplies a browser and one terminal window; the site runs in their datacentre.
1. 注册账号 / Register an account
打开 my.domcloud.co/login,用 Google 登录最省事。Open my dot domcloud dot co slash login and sign in with Google, which is the least hassle. 用第三方登录可以跳过邮箱验证;用邮箱注册则必须先点验证链接才能建站。Third-party sign-in skips email verification, whereas registering by email means you must click the verification link before creating any website.
2. 先看清免费版给你什么 / See exactly what the free plan gives you
1.5GB 存储、2GB 月出站流量、SSH、Git 集成、数据库,以及和付费版一样的功能面。1.5GB storage, 2GB monthly outbound traffic, SSH, Git integration, databases, and the same feature surface as the paid plans. CPU 和内存不单独限额,但那是共享不计量的意思,不是独占——网上“6G 免费云服务器”的说法请直接忽略。CPU and RAM aren't individually capped, but that means shared and unmetered, not dedicated, so ignore any "free 6GB cloud server" claims you've read.
3. 拿一个邀请码 / Get an invite code
免费版需要邀请码,官方指定的拿码地方就是他们的 Discord。The free plan requires an invite code, and the official place to get one is their Discord. 进 discord.gg/ee6xre2q8W,在频道里礼貌说明你想试用免费版,通常几分钟内就有人给你一个。Join discord dot gg slash ee6xre2q8W, politely say you'd like to try the free plan, and someone usually hands you one within minutes.
4. 确认码的格式对不对 / Check the code's format
邀请码是 IVME 开头再跟 10 位字母。An invite code starts with IVME followed by ten letters. 每个码有 20 或 2000 次的配额,拿到旧码可能已经用完,失效就再要一个,不用客气。Each code carries a quota of either 20 or 2000 uses, so an old code may already be exhausted. If it fails, just ask for another.
5. 建第一个网站 / Create your first website
登录后点 Create a Website,弹窗里粘上邀请码。After logging in click Create a Website and paste the invite code into the dialog. 左边是从模板起步,右边是上传或克隆现成项目;这次选左边的 Static 或 HTML 模板。The left side starts from a template and the right side uploads or clones an existing project. This time pick the Static or HTML template on the left.
6. 挑机房,别挑 x64 / Pick a server, but not x64
三个机房可选:SGA(新加坡)、NYC(纽约)、FRA(法兰克福)。Three locations are available: SGA in Singapore, NYC in New York, and FRA in Frankfurt. 免费版不能用 x64 机型,灰掉的选项不用纠结;亚洲用户选 SGA 延迟最低。The free plan cannot use x64 servers, so don't agonise over the greyed-out options. Asian users get the lowest latency from SGA.
7. 等它跑完 / Wait for the runner to finish
创建后会跳到 runner 页面,可以看到全过程进度。Creation drops you onto the runner page where you can watch the whole process. 看到 “Your website is ready!” 和打开网站的按钮,就成了。When you see "Your website is ready!" plus a button to open the site, you're done.
8. 记下访问凭据 / Note down your credentials
进 Manage 区块,那里有 SSH 用户名、密码和服务器地址。Go to the Manage section, where your SSH username, password, and server address live. Info 区块能看到存储和带宽用量,建议第一天就看一眼基线。The Info section shows storage and bandwidth usage, and it's worth glancing at your baseline on day one.
9. 打开部署面板 / Open the deploy panel
进网站里的 Setup 然后 Deploy 标签,点 Add a deployment task。Inside your website go to Setup, then the Deploy tab, and click Add a deployment task. 这个面板本质就是帮你按顺序执行 SSH 命令,起始目录固定是 ~/public_html。This panel simply runs SSH commands in order, always starting in the public_html directory.
10. 粘贴部署脚本 / Paste the deploy script
把下面那段 YAML 整段粘进去,然后点部署。Paste the whole YAML below and hit deploy. 执行顺序固定是 source 然后 features 然后 commands 最后 nginx,单次总时长上限 15 分钟。The order is always source, then features, then commands, then nginx, with a 15-minute cap per run.
11. 盯着日志看 / Watch the log
任何一条命令返回非零,整条链会立刻停下。If any command exits non-zero, the whole chain stops immediately. 所以出错位置一目了然,不用猜。That means the failure point is obvious and you never have to guess.
12. 打开网站,顺手看一眼横幅 / Open the site and meet the banner
浏览器访问你的 .dom.my.id 域名。Visit your dot dom dot my dot id domain in a browser. 第一次会看到防钓鱼横幅,点信任按钮就进去了,这是所有免费域名的标配。You'll meet an anti-phishing banner the first time; click the trust button to pass. Every free domain has one.
13. SSH 进去验证一下 / SSH in and verify
在 Mac 终端跑 ssh 你的用户名@sga.domcloud.co,密码用 Manage 里那个。In your Mac terminal run ssh with your username at sga dot domcloud dot co, using the password from Manage. 换机房就把主机名换成 nyc.domcloud.co 或 fra.domcloud.co。If you chose another location, swap the hostname for nyc dot domcloud dot co or fra dot domcloud dot co.
14. 查一下自己还剩多少空间 / Check how much room you have left
登进去跑 du -sh ~/public_html 和 df -h ~。Once in, run du -sh on your public_html and df -h on your home directory. 1.5GB 听起来不多,但静态站通常只占几 MB,真正吃空间的是数据库和上传的图片。1.5GB doesn't sound like much, but a static site is usually only a few megabytes; databases and uploaded images are what actually eat it.
15. 试试网页版编辑器 / Try the browser-based editors
回面板点 Debug Manually,能开 Web SSH、Filestash 文件管理器和 VS Code。Back in the panel click Debug Manually to open Web SSH, the Filestash file manager, and VS Code. 出门在外没带电脑也能改站,这是免费版里最被低估的一个好处。You can edit your site without your own computer, which is the most underrated perk of the free plan.
16. 需要数据库就一行开 / Turn on a database with one line
想装 CMS 就在部署脚本的 features 里加 mysql,它会自动建库。If you want a CMS, add mysql to the features list in your deploy script and it creates the database automatically. 密码会以环境变量 $MYPASSWD 提供给部署命令,不用自己抄。The password is handed to your deploy commands as an environment variable, so you never copy it by hand.
17. 别指望它对外发请求 / Don't expect it to reach outward
免费版默认开启出站防火墙,只允许白名单站点,关掉必须先升级到 Lite 或以上。The free plan enables an outbound firewall by default, allowing only whitelisted sites, and switching it off requires Lite or above. 静态站完全不受影响,但如果你的站要抓天气或汇率,基本会被挡。A static site is entirely unaffected, but a site fetching weather or exchange rates will almost certainly be blocked.
18. 每 60 天必须回来登录一次 / Log back in every 60 days
免费版有到期日,每次登录都会自动续期,所以两个月内登录一次就永不过期。The free plan has an expiry date that renews automatically on every login, so logging in once within two months keeps it alive indefinitely. 或者月末出站流量超过 50MB 也会自动续 60 天。Alternatively, exceeding 50MB of outbound traffic by month's end also renews it for another 60 days.
19. 忘记登录的后果要知道 / Know what happens if you forget
过期后有 14 天宽限,期间官方会发三封提醒邮件。After expiry you get 14 days, during which they send three reminder emails. 14 天内不登录,所有网站数据会被永久删除,所以重要内容自己也留一份。Miss those 14 days and all website data is permanently deleted, so keep your own copy of anything important.
20. 想要干净域名的一次性小技巧 / A one-off trick for a clean domain
受不了横幅的话,付一次 4.5 美元买 3 个月 Lite,切到 .domcloud.dev 域名,然后停订。If the banner bothers you, pay 4.5 dollars once for three months of Lite, switch to a dot domcloud dot dev domain, then stop subscribing. 官方明确说降回免费版后这个域名永久保留,配置也不会被回退——这是唯一一笔我认为值得花的钱,但完全可选。They explicitly state the domain stays with you forever after dropping back to free, and the config isn't reverted. It's the only spend I'd call worthwhile, and it's entirely optional.
---
部署脚本
在 Deploy 面板粘这一整段。它会清空目录、写入一个静态主页、配好 404 页面、并申请免费 HTTPS 证书:
source: clear
features:
- ssl
- ssl always
commands:
- |
cat > index.html <<'EOF'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Hello from my own host</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<main>
<h1>I have a server now</h1>
<p class="sub">Running on 1.5GB of somebody else's kindness.</p>
<ul>
<li><span>Storage</span><span>1.5 GB</span></li>
<li><span>Outbound</span><span>2 GB / month</span></li>
<li><span>SSH</span><span>yes</span></li>
<li><span>HTTPS</span><span>free, auto-renewed</span></li>
<li><span>Cost</span><span>nothing</span></li>
</ul>
<footer>Remember to log in every 60 days.</footer>
</main>
</body>
</html>
EOF
- |
cat > style.css <<'EOF'
:root { color-scheme: light dark; }
* { box-sizing: border-box; }
body {
margin: 0; padding: 4rem 1.25rem;
font: 16px/1.65 -apple-system, "Helvetica Neue", system-ui, sans-serif;
background: #fbfaf7; color: #1c1c1e;
}
main { max-width: 30rem; margin: 0 auto; }
h1 { font-size: 1.9rem; letter-spacing: -0.02em; margin: 0 0 .3rem; }
.sub { color: #86868b; margin: 0 0 2.2rem; }
ul { list-style: none; padding: 0; margin: 0; }
li {
display: flex; justify-content: space-between;
padding: .85rem 1rem; margin-bottom: .55rem;
background: #fff; border-radius: 13px;
box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
li span:first-child { color: #6e6e73; }
li span:last-child { font-weight: 600; }
footer { margin-top: 2.2rem; font-size: .82rem; color: #a5a5ab; }
@media (prefers-color-scheme: dark) {
body { background: #131315; color: #ececee; }
li { background: #1e1e21; box-shadow: none; }
li span:first-child { color: #98989d; }
}
EOF
- |
cat > 404.html <<'EOF'
<!doctype html><meta charset="utf-8">
<title>Not here</title>
<body style="font:16px/1.6 system-ui;padding:4rem;text-align:center">
<h1>404</h1><p>This page never existed. <a href="/">Go home</a>.</p>
EOF
- chmod 0644 index.html style.css 404.html
nginx:
error_pages:
- 404 /404.html
locations:
- match: /
expires: 1d
各段在做什么:source: clear 清空 ~/public_html;features 里的 ssl 申请或续期 Let's Encrypt 证书,ssl always 让 HTTP 永久跳转到 HTTPS;commands 是按顺序执行的 SSH 命令,起始目录就是 ~/public_html;nginx 最后生效,配置 404 页面和缓存时长。 What each block does: source clear empties public_html; the ssl feature requests or renews a Let's Encrypt certificate while ssl always permanently redirects HTTP to HTTPS; commands are SSH commands run in order, starting inside public_html; nginx applies last, setting the 404 page and cache duration.
之后常用的几条命令
SSH 进去以后:
# 看目录和用量
cd ~/public_html && ls -la
du -sh ~/public_html
df -h ~
# 改完文件立刻生效(静态站不需要重启)
nano index.html
# 如果以后跑了非 PHP 应用,改完代码要重启 Passenger
restart
# 看 NGINX 访问和错误日志
tail -n 50 ~/logs/access_log
tail -n 50 ~/logs/error_log
想升级成 CMS 的话
在部署脚本里把 features 换成下面这样,数据库和 PHP 一次配好:
source:
url: https://wordpress.org/latest.zip
directory: wordpress
features:
- mysql
- php latest
- ssl
- ssl always
nginx:
fastcgi: on
locations:
- match: /
try_files: $uri $uri/ /index.php$is_args$args
⚠️ 提醒一句:免费版的出站防火墙会影响 WordPress 后台在线安装插件和主题,静态站没这个问题。1.5GB 存储装 WordPress 本体没问题,但媒体库很快就会顶到上限。 One caveat: the outbound firewall will interfere with installing plugins and themes from the WordPress dashboard, whereas a static site has no such issue. 1.5GB comfortably holds WordPress itself, but a media library will hit the ceiling fast.
Related Links(相关链接):
https://domcloud.co
https://my.domcloud.co/login
https://domcloud.co/docs/intro
https://domcloud.co/docs/intro/getting-started
https://domcloud.co/docs/intro/free-plan
https://domcloud.co/docs/intro/invitation-code
https://domcloud.co/docs/intro/compare-plans
https://domcloud.co/docs/intro/compare-server
https://domcloud.co/docs/intro/security
https://domcloud.co/docs/deployment
https://domcloud.co/docs/deployment/deploy
https://domcloud.co/docs/deployment/static-site
https://domcloud.co/docs/deployment/nginx
https://domcloud.co/docs/deployment/php
https://domcloud.co/docs/features/dns
https://domcloud.co/docs/features/security
https://domcloud.co/docs/features/editor
https://domcloud.co/docs/features/database
https://domcloud.co/docs/features/linux
https://domcloud.co/docs/guides
https://domcloud.co/price
https://discord.gg/ee6xre2q8W
https://stats.uptimerobot.com/AA77Xt9Jx8
https://azure.microsoft.com/en-us
评论
发表评论