this blog is used to introduce the technology that uses Docsify to quickly build a personal knowledge share website.Docsify is a static website gen framework which convert the md file to a static webpage.

Download

We need to download these softwares:

local: node

remote server:docker nginx

docker is a tool to download develop software,like a app store, but docker serves developers.nginx is a lightweight web server.Nginx can be used as a proxy server,load balance server, static webpage server.Nginx is characterized by less RAM and high concurrency.In this blog,I will use nginx to deploy a static website.

Docker

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
31
32
33
34
35
36
37
38
39
40
# skip the download proccess of docker,only introduce how to use docker
# search xx in docker hub
docker search xx
# download the latest xx image
docker pull xx(xx:latest)
# create xx container(a image can have any amount of container)
docker run
--restart=unless-stopped # or other args like always
--name=mysql # container name
--privileged=true # security policy:allow
# Map the file/folder on the host to the file/folder on the container(two way binding).The gengeral mapping content is the log,data,configuration.You must ensure that the files or folders(the files inside are completely consistent) of both exist.How to ensure?you can use the "docker cp" to copy the folder/file in the container to the host,after deleting the container,re-creat a new container to save time.Why mapping?Modify the content of the file is very troublesome.You need to enter the container and download vim(apt-get uodate,apt-get install vim),so that it consumes time and waste space(Maybe 100MB).Finally,you must konw the path of container data/log/configuration,the path of each software is diffrent.
-v /mydata/mysql/log:/var/log/mysql #log mapping
-v /mydata/mysql/data:/var/lib/mysql # date mapping
-v /mydata/mysql/conf:/etc/mysql # configuration mapping
-v /etc/localtime:/etc/localtime:ro # others:like time mapping
# port mapping
-p 3306:3306
# image name
-d xx
# other shell
# show images list
docker images
# show running container
docker ps
# show all container
docker ps -a
# update some running arguments
docker update containername/id --aa=bb
# stop running container
docker stop/kill containername/id
# delete container(you must stop it,then you can delete it)
docker rm containername/id
# delete image
docker rmi containername/id
# view the log of containername/id
docker logs containername/id
# enter the container
docker exec -it containername/id bash
# copy the front(don't add /) to the back(need to add /),you can exchange order
docker cp containername/id:containerpath hostpath

Nginx

we will use to download nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
docker pull nginx
docker run --name=nginx --restart=always -p 80:80 -d nginx
# configuration mapping
docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf/
docker cp nginx:/etc/nginx/conf.d /usr/local/nginx/conf/
# log mapping
docker cp nginx:/var/log/nginx /usr/local/nginx/log/
# data mapping
docker cp nginx:/usr/local/src /usr/local/nginx/www
docker stop nginx
docker rm nginx
# add SSL mapping
docker run --name=nginx --restart=always --privileged=true -p 80:80 -p 443:443 -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d -v /usr/local/nginx/log:/var/log/nginx -v /usr/local/nginx/www/src:/usr/local/src -v /etc/letsencrypt:/usr/local/share/ca-certificates -d nginx

config default.conf

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
31
32
33
34
server {
listen 80;
listen [::]:80;
server_name bborange.top;
# $1 means URI,permanent means 301(forced redirect,302 means soft redirect)
rewrite ^(.*) https://$server_name$1 permanent;

location / {
root /usr/local/src/repository;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 443 ssl;
listen [::]:443;
server_name bborange.top;
ssl_certificate /usr/local/share/ca-certificates/live/bborange.top/fullchain.pem;
ssl_certificate_key /usr/local/share/ca-certificates/live/bborange.top/privkey.pem;

location / {
root /usr/local/src/repository;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

Docsify

Docsify is a node package.

1
npm install -g docsify-cli

Configuration

1
2
docsify init
docsify s -p xx (running in local port xx,default port 3000)

you can edit README.txt to change website content,but you must restart nginx.