surge免费部署https静态网站

在surge.sh搭建https静态项目或资源

前言#

如果有静态资源或者页面需要给用户做展示。但是苦于没有服务器,没有域名。那么现在用上surge就没错了。

surge的免费定价方案是:

  1. 不限发布
  2. 自定义域名
  3. 基础SSL服务(即HTTPS服务)

默认的surge.sh域名有286天免费限制,但对于个人或者小型项目开发者而言,足够使用了。

首先,surge是一个命令行工具。从特性来说就可以杜绝广告营销商的滥用(因为太麻烦了)。

安装#

首先需要安装Node.js环境:请移步Node.js官网

Windows

npm install surge -g

Mac下使用sudo进行安装,以免受读写文件限制。

sudo npm install surge -g

使用#

安装完毕之后,打开命令行工具,cd进入需要上传的文件夹(可将文件夹拖进命令行工具得到完整路径)

这里举例进入html文件夹

cd Documents/root/html

进入文件夹之后可以用ls(Mac),dir(Windows)查看目录下的文件,确认上传文件是否正确。

在该目录下输入surge即可启动surge程序

surge

返回以下内容

Welcome to surge! (surge.sh)
Login (or create surge account) by entering email & password.

      email:

第一次使用没有账号,可以直接输入邮箱进行注册。这里填写自己的常用邮箱即可,注册成功后会发送验证邮件。

Welcome to surge! (surge.sh)
Login (or create surge account) by entering email & password.

          email: xxx@xxx.com
       password: 

输入邮箱,按回车后输入密码。密码在这里是不会显示出来的,输入完成后回车继续。

Welcome to surge! (surge.sh)
Login (or create surge account) by entering email & password.

          email: xxx@xxx.com
       password: 

Running as xxx@xxx.com (Student)

        project: /Documents/root/html/
         domain: dash.surge.sh

域名这里会给一个默认xxxx.surge.sh的子域名,如果不喜欢,可以修改子域名xxxx为自己喜欢的名字。按回车继续。

   Welcome to surge! (surge.sh)
   Login (or create surge account) by entering email & password.

          email: xxx@xxx.com
       password: 

   Running as xxx@xxx.com (Student)

        project: /Documents/root/html/
         domain: dash.surge.sh
         upload: [===] 100% eta: 0.0s (2 files, 19565 bytes)
            CDN: [====================] 100%
     encryption: *.surge.sh, surge.sh (286 days)
             IP: 13x.19x.23x.12x

   Success! - Published to dash.surge.sh

最后会进入自动上传阶段,上传完成后即可通过Success! - Published to 后面的域名访问。

小技巧#

如果想更新某个域名(例:dash.surge.sh)下的文件,可以直接使用命令:

surge --domain dash.surge.sh

或 将域名保存为文件CNAME放到项目根目录下,手动创建和命令创建都行。命令如下:

echo dash.surge.sh > CNAME

这样会自动读取项目域名,更新项目内容。

更多#

surge官方网站