n/programu/yucho · 2025-01-06
注册 登录
n/program · 2025-01-06 · 532 次浏览
u/yucho荣誉会员钻石

国外免费静态网页托管—— Surge 详细使用教程

## 介绍

Surge 是荷兰的一家静态网站托管服务提供商,提供免费的静态网页托管服务。与大多数静态网页托管提供商不同的是,Surge 的网页托管服务从注册到删号除了激活账户以外全程使用命令行,几乎不需要图形界面。
在~~其官网的“价格”页面,只有两种套餐——“免费”套餐和 $30 一个月的“专业”套餐。两者在流量、存储空间、域名绑定方面都是无限的,也都可以使用 </s>surge.sh<e> 后缀的二级域名及开启 https,只是后者可为自己添加的第三方域名设置 SSL 证书,以及支持重定向、跨域设置和密码保护。

##~~ 使用

### 安装

因为 Surge 的命令行客户端是用 Node.js 编写的,因此使用前需要先安装 Node.js 和 npm(一般会自带),此处省略 N 字。
安装好 Node.js 和 npm 后,只需在命令行输入 ~~</s>npm install surge -g<e> 即可安装 Surge 。安装成功的话,输出应该是类似这样的:

npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: this library is no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

added 99 packages in 16s

6 packages are looking for funding
  run `npm fund` for details
<e>```</e></CODE>
<p>此时执行 <C><s>`</s>surge --version<e>`</e></C>,输出应该是这样的:</p>
<CODE><s>```
v0.24.6

(node:2569) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
<e>```</e></CODE>
<p>说明安装成功。</p>
<H3><s>### </s>登录/注册</H3>
<p>运行 <C><s>`</s>surge login<e>`</e></C> ,依次输入你的邮箱地址和密码(不要在意红色的报错信息),不需要注册,Surge 会自动为你创建账户并登录。操作成功的输出类似这样:</p>
<CODE><s>```
Login or create surge account by entering email &amp; password.

          email: (node:5877) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

          email: [email protected]
       password:

   Success - Logged in as [email protected].
<e>```</e></CODE>
<p>如果你是首次登录,请打开你的邮箱,点击激活链接进行激活。</p>
<H3><s>### </s>创建网站</H3>
<H4><s>#### </s>准备</H4>
<p>将网站的全部文件和文件夹放到一个文件夹里。这里我准备了一个只有 index.html 文件的文件夹,其 HTML 代码非常简单:</p>
<CODE lang="html"><s>```html
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;测试&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;这只是一个测试页面&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;
<e>```</e></CODE>
<H4><s>#### </s>部署网站</H4>
<p>进入到文件夹所在位置,运行 <C><s>`</s>surge<e>`</e></C> 。此时,你需要依次输入一些信息。首先是网站目录的路径,由于你已经进入了网站所在目录,因此直接回车即可。<br/>
接着是网站的域名,默认会生成一个 <C><s>`</s>surge.sh<e>`</e></C> 二级域名。你可以修改免费二级域名的前缀或者设置成自己的域名。如果你选择后者,你需要先将你的域名 CNAME 解析到 <C><s>`</s>na-west1.surge.sh<e>`</e></C> 。这里,我输入的域名为 <C><s>`</s>yucho-surge-demo.surge.sh<e>`</e></C> 。回车后,等待命令执行完成,网站部署成功的输出类似这样:</p>
<CODE><s>```
(node:11869) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Running as [email protected] (Student)

        project: /home/yucho/surge-demo/
         domain: yucho-surge-demo.surge.sh
           size: 1 files, 169 bytes
         upload: [====================] 100%
            CDN: [====================] 100%
     encryption: [====================] 100%

  ┌──────────────────────────────────────────────────────────────────────────────┬────────────────────┐
  │  Certificate: issuer=C = GB, ST = Greater Manchester, L = Salford, O = Sec…  │  Valid             │
  │   *.surge.sh, surge.sh                                                       │  134 more days     │
  └──────────────────────────────────────────────────────────────────────────────┴────────────────────┘
  ┌──────────┬──────────────────────────────────────────────────────────────────────────────┬─────────┐
  │          │   ns1.surge.world   ns2.surge.world     or CNAME…                            │         │
  │    NS    │   ns3.surge.world   ns4.surge.world     geo.surge.world                      │         │
  ├──────────┼──────────────────┬───────────────────────┬─────────────────────┬─────────────┼─────────┤
  │   HTTP   │   sfo.surge.sh   │   US, San Francisco   │   138.197.235.123   │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   lhr.surge.sh   │   GB, London          │   46.101.67.123     │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   yyz.surge.sh   │   CA, Toronto         │   159.203.50.177    │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   jfk.surge.sh   │   US, New York        │   159.203.159.100   │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   ams.surge.sh   │   NL, Amsterdam       │   188.166.132.94    │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   fra.surge.sh   │   DE, Frankfurt       │   138.68.112.220    │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   sgp.surge.sh   │   SG, Singapore       │   139.59.195.30     │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   blr.surge.sh   │   IN, Bangalore       │   139.59.50.135     │   D.Ocean   │   ✔ ◍   │
  │   HTTP   │   syd.surge.sh   │   AU, Sydney          │   45.76.126.95      │   Vultr     │   ✔ ◍   │
  │   HTTP   │   nrt.surge.sh   │   JP, Tokyo           │   172.104.96.133    │   Linode    │   ✔ ◍   │
  └──────────┴──────────────────┴───────────────────────┴─────────────────────┴─────────────┴─────────┘
   Live preview .............................................. 1736075801131-yucho-surge-demo.surge.sh
   Production .............................................................. yucho-surge-demo.surge.sh

   Success! - Published to yucho-surge-demo.surge.sh
<e>```</e></CODE>
<p>此时就可以访问 <URL url="http://yucho-surge-demo.surge.sh/">http://yucho-surge-demo.surge.sh/</URL> ,看看网页是否显示正常了。<br/>
<STRONG><s>**</s>注意<e>**</e></STRONG>:每次修改了网页,都要重新部署!</p>
<H4><s>#### </s>配置 https</H4>
<p>默认情况下,我们添加的网站只有 http ,这导致在国内有些地方可能会打不开,而且也会让浏览器提示“不安全”。启用 https 的方法非常简单:如果你用的是官方的二级域名,只需要在部署的时候在域名前面加上 <C><s>`</s>https://<e>`</e></C> ;如果是自己的域名,就需要用 CloudFlare 等 CDN 来配置 https 。</p>
<H4><s>#### </s>记住域名和跳过输入目录路径</H4>
<p>每次部署都需要我们输入网站目录路径和域名,太麻烦,怎么办?只需要切换到网站目录,将命令换成 <C><s>`</s>surge ./<e>`</e></C> 即可跳过输入目录路径的步骤。同时,在网站目录创建一个名为 CNAME 的文件,用文本编辑器打开它,在其中写入你需要绑定的域名并保存即可。下次部署就不需要再输入域名了。</p>
<H4><s>#### </s>自定义 404 页面</H4>
<p>准备好你想要的 404 页面,放在网站目录中,改名为 <C><s>`</s>404.html<e>`</e></C> ,重新部署即可。</p>
<H3><s>### </s>查看和删除已部署网站</H3>
<p>运行 <C><s>`</s>surge list<e>`</e></C>,可查看当前账户部署的全部网站,输出类似这样:</p>
<CODE><s>```
(node:21804) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
yucho-surge-demo.surge.sh   9 minutes ago   surge   surge.sh   Standard
surge-website.yucho.top             3 months ago    surge   surge.sh   Standard
grumpy-voice.surge.sh       7 months ago    surge   surge.sh   Standard
localhost.yucho.top         7 months ago    surge   surge.sh   Standard
<e>```</e></CODE>
<p>要删除某个网站,只需要执行 <C><s>`</s>surge teardown [域名]<e>`</e></C> 。例如我执行 <C><s>`</s>surge teardown yucho-surge-demo.surge.sh<e>`</e></C> 的输出如下:</p>
<CODE><s>```
(node:22058) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Success - yucho-surge-demo.surge.sh has been removed.
<e>```</e>
~~###~~ 退出登录 &amp; 换号

退出登录: <C>~~`</s>surge logout<e>`</e></C>
换号:不需要退出登录,运行 <C>`</s>surge login<e>`</e></C> 后输入电子邮箱地址和密码即可。
surge 命令的更多使用说明参见 <C>`</s>surge --help<e>`</e></C> 。

##~~ 参考

<URL url="https://surge.sh/help/">~~[~~官方文档<e>](https://surge.sh/help/)</e></URL>
</r>
0
12
登录后参与讨论。
海外原生IP VPS,稳定访问全球网络

还在为IP不纯、平台风控、频繁验证而烦恼? 丽萨主机海外原生IP VPS,双ISP住宅IP,覆盖美国、香港、日本、新加坡、台湾、德国、越南、英国等热门地区,适合跨境电商、社媒运营、AI工具、流媒体及海外业务使用。

lisahost.com 了解更多

12 条回复

排序
  1. tvbox 铂金 3 YEARS 2025-01-06

    不是说这个几天就关机吗

    0
  2. azhaoyihao 荣耀 水王 2025-01-06

    全程命令 太厉害了

    0
  3. kefeng 黄金 2025-01-06

    技术大佬 最爱

    0
  4. yucho 荣誉会员 钻石 楼主 2025-01-06

    @"传说007"#p203912 你搞错了吧?这个是静态网页托管,不存在关机的问题,我有个网站已经部署9个月了。。。

    0
  5. ClassmateShen ⭐️ 王者 MANAGER 2025-01-06

    Surge?我以为是那个Surge(色🐔)

    0
  6. yucho 荣誉会员 钻石 楼主 2025-01-06

    @"叫我沈同学"#p203984 你不对劲:ac01:

    0
  7. newwstd 白银 2025-01-06

    太麻烦了,还是喜欢简单点的哈,静态也没什么大用处哈

    0
  8. Hirm 黄金 不离不弃 2025-01-06

    能托管 node吗

    0
  9. yucho 荣誉会员 钻石 楼主 2025-01-06

    @"Hiram"#p204130 这是静态网页托管

    0
  10. yoursunny 黄金 2025-01-06

    这么多 DeprecationWarning,是不是意味着系统已经不再维护了?

    0
  11. yucho 荣誉会员 钻石 楼主 2025-01-06

    @"yoursunny"#p204163 上次更新是在2024年8月12日,估计是觉得能跑就行了

    0
  12. laddfkuo 白银 2025-01-06

    高手

    0