This page looks best with JavaScript enabled

Host a static website on Netlify

 ·  β˜• 2 min read

Prepare

Netlify Intro

Netlify is a popular static website Host service,
and its free quota is very suitable for general users

You can customize the subdomain or use your own domain name,
and also provide free SSL

It is very convenient that Netlify will automatically deploy when push to GiuHub Repository

Preare your static website

Here is an example created by Hugo (How to create a static web by Hugo)

First, add netlify.toml to root of your site workspace
Note that HUGO_VERSION

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[build]
publish = "public"
command = "hugo --gc --minify"

[context.production.environment]
HUGO_VERSION = "0.71.0"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"

[context.split1]
command = "hugo --gc --minify --enableGitInfo"

[context.split1.environment]
HUGO_VERSION = "0.71.0"
HUGO_ENV = "production"

[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"

[context.deploy-preview.environment]
HUGO_VERSION = "0.71.0"

[context.branch-deploy]
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"

[context.branch-deploy.environment]
HUGO_VERSION = "0.71.0"

[context.next.environment]
HUGO_ENABLEGITINFO = "true"

Use git

1
2
3
git init	# Create an empty Git repository
git add -A	# Add files
git commit -m "Initial commit"	# commit to master

Go to GitHub create a repository (private is allowed)


create github repository

Copy the repository link

https://github.com/YOUR_GITHUB_NAME/REPOSITORY_NAME.git

Push local to GitHub

1
2
git remote add origin https://github.com/YOUR_GITHUB_NAME/REPOSITORY_NAME.git	# add remote repository, named origin
git push -u origin master	# push to remote

You can see your files on GitHub Repository

Deploy on Netlify

Go to Netlify, login and click New site from Git


new site from git

Click GitHub


new site from git step 1

Authorize Netlify access GitHub


authorize netlify

Select the repository


select repository

Click it


new site from git step 2

configuration has been read from netlify.toml

Deploy site


deploy setting

I Failed…


deploy failed

Here is the error

Error: Error building site: failed to render pages: JSON parse error: unexpected comma character on line 9 and column 20
    9:     "description": ,

I don’t find the reason, so decided to remove --minify
It works.

Then change to your own domain, click Deploy settings


deploy success

Switch to Domain management tab and click Add custom domain


add custom domain

Fill in your domain name


enter custom domain

click Check DNS configuration


check dns configuration

Copy that text, go to your domain name provider and add CNAME
Wait for a few minutes


add cname

Back to Netlify and click Verify DNS configuration


verify dns configuration

If there is no problem, it will succeed.

Done

Share on
Support the author with

JIHONGO
WRITTEN BY
JIHONGO
A Person