一、hexo

hexo  + Matery主题 + Nginx + 阿里云 搭建个人博客网站

hexo文档:https://hexo.io/zh-cn/docs/

早期被推荐用hexo,当时胡乱搭建了一个,放在了github上面,后面又转移到gitee上,最后又删掉了仓库,仍旧用回了博客园。后来发现,自己还是想建一个站。原本想自己 vue + python + Django 搞一个的,最后的结果嘛,看看标题就清楚了。

二、Matery主题

这个主题是在将博客网站转移到gitee上的时候发现的,那会儿就感觉不错,这次搭建的时候,特意找出来用了,非常感谢作者将这个主题分享了出来。

主题github:https://github.com/blinkfox/hexo-theme-matery

中文说明:https://github.com/blinkfox/hexo-theme-matery/blob/develop/README_CN.md

四、Nginx

最开始看的这个教程:https://www.bilibili.com/video/BV1zJ411w7SV

后面使用docker 搭建Nginx容器,参考博客:https://www.jianshu.com/p/f2c6ad35fbb0

上面博客这位up主在B站上发的教程: https://www.bilibili.com/video/BV1YE411E7Xr

三、阿里云

这个上面的那位up主的教程里也有,详细的人家博客里面都有,搜一下就行

ps:后面如果想写的话,会写一个详细的。

-----------2021.06.05 原先阿里云到期,重新部署---详细版---------------

重新采购了一台阿里的ECS,将原先博客部署到这上面,下面为记录一台新设备部署项目的过程:

本次系统镜像使用的是:ubuntu 20.0

先更新一下当前安装的软件包:

 sudo apt-get update

已安装的软件升级

 sudo apt-get upgrade -y

安装docker:

使用官方安装脚本自动安装(本次安装使用的这个):

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

或使用国内 daocloud 一键安装(这个没试):

curl -sSL https://get.daocloud.io/docker | sh

安装完毕后,通过命令检查:

# 命令:
docker  

# 输出:
Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var
                           and default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit


安装docker前的准备工作

# 创建文件夹,用来将容器内的文件映射到外部服务器上的文件夹内,方便后期进行调整
mkdir /home/nginx
mkdir /home/nginx/conf
mkdir /home/nginx/conf.d
mkdir /home/nginx/logs
mkdir /home/nginx/www

# 进入conf文件夹,创建配置文件
cd /home/nginx/conf

# 创建配置文件
touch nginx.conf

# 编辑配置文件
vim nginx.conf

# 配置内容
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

docker安装 nginx

# 拉取nginx镜像
docker pull nginx:latest

# 查看镜像
docker images

# 启动镜像,创建容器(将服务器的80端口映射到 nginx的80端口上;-v 宿主机器的文件夹:容器的文件夹)
docker run \
    --name nginx-blog \
    -p 80:80 \
    -v /home/nginx/www:/usr/share/nginx/html \
    -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
    -v /home/nginx/logs:/var/log/nginx \
    -v /home/nginx/conf.d:/etc/nginx/conf.d \
    -d nginx


# 命令含义

–name nginx-blog:将容器命名为 nginx-blog

-p 80:80:端口映射 冒号前是本机端口,冒号后是容器端口

-v /home/nginx/www:/usr/share/nginx/html:将我们自己创建的 www 目录挂载到容器的 /usr/share/nginx/html 目录

-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:将我们自己创建的 nginx.conf 文件挂载到容器的 /etc/nginx/nginx.conf 文件

-v /home/nginx/logs:/var/log/nginx:将我们自己创建的 logs 挂载到容器的 /var/log/nginx 目录

-v /home/nginx/conf.d:/etc/nginx/conf.d:将我们自己创建的 conf.d 挂载到容器的 /etc/nginx/conf.d 目录

-d nginx:以守护进程的方式启动 nginx

配置项目

# github 配置免密登录
#1. 在Ubuntu的~/.ssh目录下生成SSH的公私钥;
#2. 上传生成的公钥至git服务器;
#3. 下次使用git就可以直接免密登录;
cd ~/.ssh
# 如果存在 id_rsa 和 id_rsa.pub,则copy id_rsa.pub 内容到github上  
# 如果没有,则生成
ssh-keygen

cat id_rsa.pub

# 将内容复制到 github -> setting(个人setting,非项目settings)

# 在 /home/nginx/www 目录下克隆 项目静态文件
git clone 项目git仓库(使用ssh方式,复制的时候,第一次需要输入账号密码,下一次就不需要了)

hexo  + Matery主题 + Nginx + 阿里云 搭建个人博客网站
hexo  + Matery主题 + Nginx + 阿里云 搭建个人博客网站
hexo  + Matery主题 + Nginx + 阿里云 搭建个人博客网站

# nginx.conf 配置调整功能
http {
	......此处省略,在内部追加即可
    charset utf-8;
    server {
        listen 80;
        server_name  主机IP;

        location / {
            # 上方的/home/nginx/www 路径与容器中的 /usr/share/nginx/html 对应
            # root /usr/share/nginx/html  默认路径
            root   /usr/share/nginx/html/xt12321/public;  # 此处填写theme生成的静态文件路径
            index  index.html;
        }
    }
}

相关文章: