Skip to content
0

从零开始搭建博客网站

1. 购买云服务器

我买的是阿里云的新用户每年99元服务器(买一年可再续一年,相当于可用2年),每到第2年都可接着续一年(已验证属实),相当于一直都是99元/年。

2. 购买域名

根据自己需要选择,每种价格有差异,偏僻的域名很便宜。我在阿里云上买了5年的域名,总共161元,新买的比较便宜,续期的费用就贵了。

3. 申请域名ICP备案(免费)

使用阿里云的服务器,先在阿里云上申请,会有客服打电话确认你的申请信息,然后帮你提交到工信部。所需材料:

  • 身份证正反面
  • 上传自己阅读一段文字的视频
  • 下载《互联网信息服务备案承诺书》打印并签名+手印(淘宝几块钱就能买)

4. 网站SSL证书(免费)

提示

如果你不想用 HTTPS 可跳过此步骤。

我使用的是免费的 Let's Encrypt,如何使用可参考链接

standalone方式生成:

shell
certbot certonly --standalone -d 你的域名 --email 你的邮箱

nginx方式生成(需要先安装Nginx):

shell
# --nginx-server-root指定nginx配置文件路径
certbot certonly --nginx --nginx-server-root=/root/nginx/conf -d 你的域名 --email 你的邮箱

Let's Encrypt 的证书有效期只有90天,可在过期前30天内续期,超过前30天续期会跳过:

console
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/wuguojing.cn.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Certificate not yet due for renewal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following certificates are not due for renewal yet:
  /etc/letsencrypt/live/wuguojing.cn/fullchain.pem expires on 2025-10-18 (skipped)
No renewals were attempted.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

可以使用 crontab 定时任务来自动续期:

0 0 1 */2 * /usr/local/bin/nginx -s stop && certbot renew && /usr/local/bin/nginx

注意

不要频繁续期,Let's Encrypt 是有速率等一些限制的,详细可查看官网。

5. 部署网站(免费)

配置文件 conf/nginx.conf 如下(仅供参考):

nginx
#user  nobody;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  wuguojing.cn;
        # location / {
        #    root   blogs;
        #    index  index.html index.htm;
        #}
        return 301 https://$server_name$request_uri;
    }

    # HTTPS server
    server {
        listen       443 ssl;
        server_name  wuguojing.cn;

        ssl_certificate      /etc/letsencrypt/live/wuguojing.cn/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/wuguojing.cn/privkey.pem;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+D5;

        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

        # ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        add_header Strict-Transport-Security "max-age=31536000";

        location / {
            # blogs就是vitepress构建的dist目录,我这里重命名而已,与conf目录同一级别
            root   blogs;  
            index  index.html index.htm;
            try_files $uri $uri.html $uri/ =404;
            error_page 404 /404.html;
            error_page 403 /404.html;

            location ~* ^/assets/ {
                expires 1y;
                add_header Cache-Control "public, immutable";
            }
        }
    }
}

6. 申请网安备案号(免费)

尽量在网站开通后的一个月内申请。需注意提交主体可能不会单独审核,需要同时提交另一项业务备案,也就是说单独申请主体,可能不会等到审核结果。

需要提供的材料:

  • 身份证正反照
  • 手持身份证照
  • 域名证书(基本上云服务提供商都会有)

使用云服务很简单,大概10分钟就申请完了,因为大部分信息都是云服务商那边的,他们都会提供。参考链接:阿里云

提示

你需要把ICP备案号和网安备案号放在你的网站底部,并使用指定的链接跳转。

综上,一年的费用就是 99+32=131 元,还算便宜吧!

博客主题

我使用的博客主题基础模板已经上传到 GiteeGithub 了,代码已经包含 Github Pages 部署脚本,代码更新后就会自动执行 Action。

演示地址