, 2 min read
Hosting Static Content with surge.sh
When you want totally hassle free hosting of static HTML then surge.sh is very attractive. It is easy to set-up and free of charge for most private users. It offers https out of the box from sectigo.com. It does not offer PHP, MySQL/MariaDB, CGI, Perl, etc. Just static HTML with CSS, JavaScript, images, etc. Your static content will be hosted on Your_Domain.surge.sh
.
Steps to follow:
- Install surge:
npm install surge
cd
to your directory with static content: Typesurge
It cannot be easier. If you do not want to enter the domain name over and over again, you can store this chosen domain name in file CNAME
and you won't be asked the next time:
echo Your_Domain > CNAME
The surge command offers the following options.
$ surge --help
surge – single command web publishing. (v0.21.3)
Usage:
surge <project> <domain>
Options:
-a, --add adds user to list of collaborators (email address)
-r, --remove removes user from list of collaborators (email address)
-V, --version show the version number
-h, --help show this help message
Additional commands:
surge whoami show who you are logged in as
surge logout expire local token
surge login only performs authentication step
surge list list all domains you have access to
surge teardown tear down a published project
surge plan set account plan
Guides:
Getting started surge.sh/help/getting-started-with-surge
Custom domains surge.sh/help/adding-a-custom-domain
Additional help surge.sh/help
When in doubt, run surge from within your project directory.
Your e-mail and encrypted password are stored in $HOME/.netrc
.
The script surge
will not honor symbolic links in your deployment directory. For example, an image directory will not get copied over to surge.sh.
My static site on surge.sh is here: eklausmeier.surge.sh.
Here is a session transcript.
$ /tmp/build: echo eklausmeier.surge.sh > CNAME
$ /tmp/build: surge
(node:36729) [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 Elmar.Klausmeier@gmail.com (Student)
project: /tmp/build/
domain: eklausmeier.surge.sh
size: 2495 files, 420.0 MB
upload: [=========================] 100%
CDN: [=========================] 100%
encryption: [=========================] 100%
┌──────────────────────────────────────────────────────────────────────────────┬────────────────────┐
│ Certificate: issuer=C = GB, ST = Greater Manchester, L = Salford, O = Sec… │ Valid │
│ *.surge.sh, surge.sh │ 153 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 ................................................... 1734382209728-eklausmeier.surge.sh
Production ................................................................... eklausmeier.surge.sh
Success! - Published to eklausmeier.surge.sh