hexo + next主题 自购域名+HTTPS超详细部署方法在CentOS(服务端)+Windows(客户端)

新手建议通篇看完再尝试,因为本渣也是0基础开始的搭建的,一开始连Linux命令行都不懂,经验非常通用

开通阿里云服务器

登录阿里云 https://cn.aliyun.com/ 并注册一个账号

购买一个【轻量应用服务器】
选择2C4G的服务器即可,那家有优惠就选那家,不一定是阿里云。系统我选择了CentOS 8.2,剩余都是全默认,没有加任何配置和服务。
PS:其实2C2G就够用,选小一点的,明年续费会便宜一点。

图片

我选择的配置是2核CUP,内存4G,云盘(硬盘)60G,带宽(非流量)4Mbps(不是4MB/s)

图片

初始化云服务器

购买完成就重置root的密码,阿里云会重启机器。请记住root的密码,后面用ssh登录做运维的时候使用。

图片

在防火墙必须开启80和22端口。

  • 80是访问博客用的;
  • 22是远程用xshell和xftp控制电脑的;
  • 后续上了证书还需要开443端口。

图片

配置云服务器

命令行可以连xshell来操作,也可以用阿里云自带的网页形式workbench root

图片

网页形式workbench root连上了

图片

用xshell连上了,个人是可以免费激活xshell的,只需要注册一下

图片

使用命令行对系统做一个简单的检查
检查一下硬盘df -h
/dev/vda1 是总磁盘的可用量,扣除系统的其他分区还有56G,足够使用了。

图片
图片

CPU内存状态检查:top
%Cpu(s) - id 是CPU的空闲时间
MiB Mem - free 是内存未被占用量

图片

安装gcc gcc-c++

确保用root用户操作

1
2
3
4
#安装gcc gcc-c++
yum install -y gcc gcc-c++

#RedHat、CentOS、Fedora这三款系统是几乎一样的,都可以用yum命令,其他系统就不行了。

安装PCRE库

确保用root用户操作

1
2
3
4
5
#安装PCRE库
cd /usr/local/ ##cd到这个目录里面下载文件

#这个命令是下载具体网址的文件,这是下载的运行命令行的目录中即/usr/local/中
wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz

图片
PS:pcre一般下载最新版即可,不一定是这里的8.37
图片

1
tar -xvf pcre-8.37.tar.gz  #解压这个包

图片

1
2
3
cd pcre-8.37  #包被解压到pcre-8.37这个文件夹里面了,所以在cd进去

./configure #执行里面的configure进行配置

图片

1
2
3
4
make && make install  --进行编译并安装

#确认版本,有版本号返回就证明成功了
pcre-config --version

图片
看到有版本号返回就证明安装PCRE库成功了

安装其他依赖

确保用root用户操作

1
2
#安装 openssl 、zlib 、 gcc 依赖
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

安装Nginx(Nginx相关的内容超难,要多看几遍)

确保用root用户操作

1
2
3
4
5
#安装nginx
cd /usr/local/ #还是到这个目录里面下载文件

#继续下载nginx包到本命令执行的目录
wget http://nginx.org/download/nginx-1.17.9.tar.gz

图片
PS:一般下载最新版的Nginx即可,不一定是这里的1.17.9版
图片

1
tar -xvf nginx-1.17.9.tar.gz  #解压包到本命令执行的目录

图片

1
2
3
cd nginx-1.17.9  #解压出来的在nginx-1.17.9目录下,cd进去

./configure #进行配置

图片

1
2
3
make && make install  #进行编译并安装

ps -ef | grep nginx #查看nginx是否在启动

图片

创建hexo网站文件的存放目录

新建**/home/www/website**文件夹,这是放置静态页面index.htm主页的地方,让nginx代理到这里找到index.htm文件就能浏览网站了。

确保用root用户操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#确保是在root中操作
su root

输入密码

cd /home #进入home文件夹

mkdir www #新建www文件夹,小写

cd www #进入www文件夹

mkdir website #新建website文件夹

#修改文件夹权限 这步很重要 视频中没有提及

chmod 777 /home/www/website #授权所有用户组都可以更改

chmod 777 /home/www #授权所有用户组都可以更改

图片

修改nginx.conf

通过vim或vi命令,或xftp来修改/usr/local/nginx/conf目录下的nginx.conf文件中的这两个地方,换成
root /home/www/website
当然,如果你的hexo静态网站文件,是在另外一个目录,改成对目录即可。 这就是Nginx代理指向的文件目录。
图片

确保用root用户操作

1
2
nginx -s reload  #修改完conf文件,用这个命令可以让其生效
netstat -lnpt #查看端口有没有被启用

图片

配置nginx脚本

在/etc/init.d/路径下添加脚本文件,名称为nginx,内容如下。人员用vim或vi添加。
图片

确保用root用户操作

把下面这段话粘贴到nginx里面。

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
#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
1
chmod +x nginx  #继续在在/etc/init.d/路径下,给这个文件赋权
1
2
3
4
5
6
7
#这个功能是用来停止启动nginx的,重启完服务器后记得启动一下
service nginx start #启动
service nginx stop #停止
service nginx reload #重启
ps -ef | grep nginx #查看nginx是否在启动

http://公网IP #可以用来检查nginx有没有启动,有nginx的404错误就是成功启动了

在/home/www/website中还没有index.html文件之前,返回404错误,就是Nginx正确配置的一种表现。因为Nginx没有找到文件,返回了标准的错误。
图片

安装nodejs(服务端)

确保用root用户操作

1
2
3
4
5
6
cd /home #建议先回到home目录,不是必须
#下载并运行Node.js的安装脚本,以在Linux系统中安装Node.js。
curl -sL https://rpm.nodesource.com/setup_10.x | bash -

yum install -y nodejs #利用yum命令来安装nodejs
#安装好nodejs同时也安装好npm命令

查看node和npm的版本,有返回值证明安装nodejs成功了

1
2
node -v
npm -v

图片

安装git

确保用root用户操作

1
2
3
yum update -y #先更新列表,确保安装的git是最新版本
yum install -y git #然后再安装git
#再看看git的版本

图片

1
2
3
4
5
6
7
chmod 740 /etc/sudoers  #给/etc/sudoers赋权

vi /etc/sudoers #修改/etc/sudoers 当然也可以用xftp来修改,见下图

#加入git ALL=(ALL) ALL 见下图

chmod 400 /etc/sudoers #修改完后,把文件权限改小

图片

配置秘钥,让Windows免密登录云服务器

确保用root用户操作

1
2
adduser git      #新建一个叫git的linux账号
sudo passwd git #并给git并给这个用户设置密码,牢记这个密码,后面要用

确保用git用户操作

这小节操作复杂,要多看几次再操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
su git  #切换到git用户

cd ~ #去到git用户的主目录/home/git

mkdir .ssh #在/home/git里面创建一个.ssh的文件夹

cd .ssh #cd进入这个/home/git/.ssh文件夹

vi authorized_keys
#创建一个authorized_keys的文件,文件名千万别打错
#把windows的登录用户中的C:\Users\{用户名}\.ssh 下面的 id_rsa.pub的内容复制出来,
#放在authorized_keys文件中,当然用xftp放也行。
#如果没有找到windows的id_rsa.pub文件,
#在本地电脑打开powerShell,创建密钥。创建密钥的命令是 ssh-keygen -t rsa
#如果你已经有了密钥就不用再次创建了。

chmod 600 ~/.ssh/authorized_keys #给文件赋权

chmod 700 ~/.ssh #给文件夹赋权

把windows的登录用户中的C:\Users{用户名}.ssh 下面的 id_rsa.pub的内容复制出来,放在/home/git/.ssh目录中的authorized_keys文件中,当然用xftp放也行。
图片

配置好后,在windows的powershell用ssh -v {linux用户名}@{linux公网IP} 命令来尝试脸上服务器
图片
返回git账号就证明成功了
图片

这小节要达到的目的是,用git用户来免密登录服务器。用ssh命令来测试是否成功。后面网站文件上传到服务器,就需要免密登录上传。

创建git空仓库

确保用git用户操作

1
2
3
4
5
6
7
cd ~  #回到git的home/git目录中

#初始化一个空仓库
git init --bare blog.git

#修改home/git目录中这个post-receive文件,把下面那句话插进去。
vi ~/blog.git/hooks/post-receive

图片
把这句话git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f写入post-receive文件

/home/www/website 这是放博客静态网站文件的地方
/home/git/blog.git 这是放hexo库的地方

配置Windows客户端

安装nodejs和git

在windows下载安装nodejs,去官网下载安装包安装就好。
https://nodejs.org/en/download
图片
在windows下载安装git,去官网下载安装包安装就好。
https://git-scm.com/download/win
图片
在power shell中查看版本是否安装成功
图片

初始化hexo

创建一个目录来初始化我们的hexo
如C盘下的blog目录下创建一个hexo目录,以后所有hexo命令都要在这个目录下执行才会有效。
图片

接下来所有命令都可以在hexo部署文件夹用鼠标右键打开open git bash here来运行

1
2
npm install -g hexo-cli  #在hexo的目录打开命令行工具执行全局安装
#在power shell执行也行,但是不建议了

图片

1
2
3
hexo init #要在你想出初始化的目录中打开 右键open git bash here来运行
#运行完,就会在这个文件夹下面创建hexo的初始化文件
npm install #并且继续执行这个命令来安装相关依赖

图片

配置_config.yml文件

在_config.yml文件的最后配置如下内容

1
2
3
4
deploy:
type: git
repo: git@120.55.168.254:/home/git/blog.git ##用户名@公网IP:服务端hexo库的路径
branch: master

图片

发布浏览博客

最后是hexo命令的四板斧

1
2
3
4
5
hexo s     #可以通过http://localhost:4000/本地浏览效果
hexo clean #清理网站静态文件
hexo g #重新生成网站静态文件
hexo d #就是执行deploy命令,把文件上传到服务器的/home/www/website目录中
#幸运的话就可以通过公网IP访问到博客了

图片
通过hexo s命令,可以通过浏览器在http://localhost:4000/中访问到本地博客文件
图片

通过hexo d能把博客文件上传到云服务器中
图片
图片

通过公网IP,能访问到博客。下一步就是要申请域名,用域名来访问我们的博客了。
图片

PS: 最近在Fedora上安装Hexo无法使用简单命令了,下图仅供参考。
图片

使用next主题美化(7.8.0版)

这里的美化都是基于7.8.0版的,8.x版基本都一样,但是会有一点不一样。

安装next主题

https://theme-next.iissnan.com/getting-started.html这个网址有安装方法及使用方法

方法一:(网络原因一般不会成功)

在/home/brian/hexo里面执行git clone https://github.com/iissnan/hexo-theme-next themes/next
图片

方法二:(成功率较高)

下载源码,解压到hexo/themes里面,并改名为next
https://github.com/theme-next/hexo-theme-next/releases/tag/v7.8.0
图片

PS:如果无法打开下载地址,尝试本渣的这个方法:如何修改hosts连接上github

然后,改hexo目录下的_config.yml文件,修改前最好备份一下。
图片
hexo s尝试一下,就能看到next主题的效果了。
图片

主题模版scheme:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
# ---------------------------------------------------------------
# Scheme Settings 主题设置
# ---------------------------------------------------------------
# 主题预设,4选1
# Schemes
scheme: Muse
#scheme: Mist
#scheme: Pisces
#scheme: Gemini

# Dark Mode 暗黑模式
darkmode: false

图片

菜单menu:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# ---------------------------------------------------------------
# Menu Settings 菜单设置
# ---------------------------------------------------------------

# Usage: `Key: /link/ || icon`
# Key is the name of menu item. If the translation for this item is available, the translated text will be loaded, otherwise the Key name will be used. Key is case-senstive.
# Value before `||` delimiter is the target link, value after `||` delimiter is the name of Font Awesome icon.
# When running the site in a subdirectory (e.g. yoursite.com/blog), remove the leading slash from link value (/archives -> archives).
# External url should start with http:// or https://
menu:
home: / || home
#about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat

# Enable / Disable menu icons / item badges.
menu_settings:
icons: true
badges: true #开启/关闭菜单文章统计

图片

增加标签页

1
hexo new page tags

在新建的C:\blog\HEXO\source\tags目录里面的index.md文件里面加入参数 type: "tags"
图片

增加分类页

1
hexo new page categories

在新建的C:\blog\HEXO\source\categories目录里面的index.md文件里面加入参数 type: "categories"
图片

社交(联系)social:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Social Links
# Usage: `Key: permalink || icon`
# Key is the link label showing to end users.
# Value before `||` delimiter is the target permalink, value after `||` delimiter is the name of Font Awesome icon.
social:
#GitHub: https://github.com/yourname || github
E-Mail: mailto:113191814@qq.com || envelope
#Weibo: https://weibo.com/yourname || weibo
#Google: https://plus.google.com/yourname || google
#Twitter: https://twitter.com/yourname || twitter
#FB Page: https://www.facebook.com/yourname || facebook
#StackOverflow: https://stackoverflow.com/yourname || stack-overflow
#YouTube: https://youtube.com/yourname || youtube
#Instagram: https://instagram.com/yourname || instagram
#Skype: skype:yourname?call|chat || skype

social_icons:
enable: true #是否显示icons图片
icons_only: false #只是显示icons图片
transition: false

图片

头像avatar:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
# Sidebar Avatar
avatar:
# Replace the default image and set the url here. #头像路径文件
url: /images/avatar.jpg
# If true, the avatar will be dispalyed in circle. #圆形显示
rounded: false
# If true, the avatar will be rotated with the cursor. #随着光标旋转
rotated: false

图片

语言language:

修改HEXO\下的_config.yml文件

1
language: zh-CN

语言参数选择的是C:\blog\HEXO\themes\next\languages里面的文件名
图片

回到顶部back2top:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
back2top:
enable: true
# Back to top in sidebar.
sidebar: false
# Scroll percent label in b2t button. # 回到顶部的百分比显示
scrollpercent: true

图片

侵权声明copyright:

修改HEXO\themes\next下的_config.yml文件

1
2
# If not defined, `author` from Hexo `_config.yml` will be used.
copyright: 本站内容归www.brian-zzh.cn站长所有 #侵权声明

图片

ICP备案编号 beian:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
# Beian ICP and gongan information for Chinese users. See: http://www.beian.miit.gov.cn, http://www.beian.gov.cn
beian:
enable: true
icp: 粤ICP备2023100809号
# The digit in the num of gongan beian.
gongan_id: 网公安编号申请中
# The full num of gongan beian.
gongan_num: 网公安编号申请中
# The icon for gongan beian. See: http://www.beian.gov.cn/portal/download
gongan_icon_url: /images/icp.png

图片

建站时间since:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#底部内容
footer:
# Specify the date when the site was setup. If not defined, current year will be used.
since: 2023
# 建站日期,默认是当年

# Icon between year and copyright info.
icon:
# Icon name in Font Awesome. See: https://fontawesome.com/v4.7.0/icons/
# `heart` is recommended with animation in red (#ff0000).
name: user
# If you want to animate the icon, set it to true.
animated: false
# Change the color of icon, using Hex Code.
color: "#808080"

图片

启用搜索功能hexo-generator-searchdb(第三方)

https://theme-next.iissnan.com/third-party-services.html#search-system 参考安装方法
https://github.com/theme-next/hexo-generator-searchdb 参见提供作者

1
2
# 在hexo的目录执行这个语句
npm install hexo-generator-searchdb --save

图片

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Local Search 开启本地搜索,需要安装hexo-generator-searchdb插件
# 安装方法见https://theme-next.iissnan.com/third-party-services.html#search-system
# Dependencies: https://github.com/theme-next/hexo-generator-searchdb
local_search:
enable: true
# If auto, trigger search by changing input.
# If manual, trigger search by pressing enter key or search button.
trigger: auto
# Show top n results per article, show all results by setting to -1
top_n_per_article: 10
# Unescape html strings to the readable one.
unescape: false
# Preload the search data when the page loads.
preload: false

图片

百度统计baidu_analytics:

https://tongji.baidu.com/ 登录这里去注册一个账号,再注册一个网站然后获得监控ID
图片
将ID放到这里

修改HEXO\themes\next下的_config.yml文件

1
2
# Baidu Analytics 开启百度统计
baidu_analytics: 7**************8 # 输入在百度统计中的ID

在百度里面就能看到访问数据
图片

不蒜子统计busuanzi_count:

修改HEXO\themes\next下的_config.yml文件

1
2
3
4
5
6
7
8
9
10
# Show Views / Visitors of the website / page with busuanzi.
# Get more information on http://ibruce.info/2015/04/04/busuanzi
busuanzi_count: #不蒜子统计
enable: true
total_visitors: true
total_visitors_icon: user
total_views: true
total_views_icon: eye
post_views: true
post_views_icon: eye

非常方便的功能,在这个主题中直接集成了
图片

Next主图特有高亮显示方式

图片
在编写md文件的时候直接用下面的代码

1
2
3
4
5
6
{% note default %} 要标记的内容 {% endnote %}
{% note primary %} 要标记的内容 {% endnote %}
{% note success %} 要标记的内容 {% endnote %}
{% note info %} 要标记的内容 {% endnote %}
{% note warning %} 要标记的内容 {% endnote %}
{% note danger %} 要标记的内容 {% endnote %}

评论Valine(Next 7.8.0版)

8.x的支持方式不一样,请看下面next V8的内容,会晚点补充

https://leancloud.cn 创建一个开发版的应用
图片
找到AppID和AppKey,填入对应位置。

修改HEXO\themes\next下的_config.yml文件

图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Valine
# For more information: https://valine.js.org, https://github.com/xCss/Valine
valine:
enable: true
appid: 这里填你申请到的appid # Your leancloud application appid
appkey: 这里填你申请到的appkey # Your leancloud application appkey
notify: false # Mail notifier
verify: false # Verification code
placeholder: 留下你的想法吧 # Comment box placeholder
avatar: mm # Gravatar style
guest_info: nick,mail,link # Custom comment header : nick,mail,link
pageSize: 10 # Pagination size
language: # Language, available values: en, zh-cn
visitor: false # Article reading statistic
comment_count: true # If false, comment count will only be displayed in post page, not in home page
recordIP: true # Whether to record the commenter IP
serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in)
#post_meta_order: 0

开发版不知道够不够用,尝试一段时间再算吧。不行就研究一下能不能再部署个Twikoo
图片

域名配置

域名购买与解析

阿里域名购买地址:https://wanwang.aliyun.com/
图片
域名解析地址:https://dns.console.aliyun.com/
一般在阿里购买的域名是自动配置好的
图片

SSL证书配置

可以在FreeSSL.cn里面买免费的
阿里云里面也有20个免费的,但是二级域名都是占一个,不过有效期好像3个月,建议尽早申请完20个备用。
申请时候的选项跟我一样就好
图片
申请完就下载nginx的,会有两个文件。key和pem文件。
图片
要把这两个文件放在服务器端的etc/ssl里面
图片

修改Nginx让大家可以默认通过https来访问(这里很难,大家多试试)

通过vim或vi或xftp命令修改/usr/local/nginx/conf目录下的nginx.conf文件
修改nginx.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

#user nobody;
worker_processes 1;
#worker_processes是并发处理服务的配置,值越大,可以支持的并发处理量越多,但是会受到硬件、软件等设备的制约。

#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;
#这里可能填localhost,要测试一下
server_name www.brian-zzh.cn;
#下面这条是把80端口http访问跳转去443端口https访问
rewrite ^/(.*)$ https://www.brian-zzh.cn:443/$1 permanent;

#charset koi8-r;

#access_log logs/host.access.log main;

#location / {
# root /home/www/website;
# index index.html index.htm;
#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /home/www/website;
#}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server

server {
listen 443 ssl;
server_name www.brian-zzh.cn;

ssl_certificate /etc/ssl/brian-zzh.cn.pem;
ssl_certificate_key /etc/ssl/brian-zzh.cn.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
root /home/www/website;
index index.html index.htm;
}
}

}

这是我对Nginx配置的理解,大家按照自己的情况配置
图片
这是要注意的配置地方
图片

在usr/local/nginx-1.17.9里面执行

1
2
3
4
5
6
7
8
#这个语句是配置ssl支持,要在解压出来的nginx文件夹里面执行,如:usr/local/nginx-1.17.9
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
#继续在这个文件夹里面只执行make命令,二进制安装
make
#备份一下/usr/local/nginx/sbin/nginx文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#用objs/nginx去替换/usr/local/nginx/sbin/nginx
cp objs/nginx /usr/local/nginx/sbin/nginx #要点y,回车确认替换
1
2
3
4
5
6
7
8
9
10
11
##看nginx的版本
[root@iZuf62d45asvfbnolo730fZ nginx-1.17.9]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.17.9
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#看到ssl字样,就证明看装成功了

#用netstat命令看看80和443端口有没有被监听成功
netstat -lnpt

域名ICP备案

域名ICP备案我是直接在阿里上做的,因为阿里会免费帮你初审,比较省事。阿里的流程指引非常清晰,这里就简单贴图给大家看看。
图片

填写信息

首先阿里云的账号是手机、邮箱、实名验证都要OK。
图片

这里要按照阿里的要求填写资料,并且上传身份证和打印一份《互联网信息服务备案承诺书》签字打手指印。
图片

阿里初审

初审大概需要1~2周,特别注意网站名有起名规定,还有网站描述要大于20个字。还需要钉钉视频拿着身份证确认身份。我第一次没有过,因为是起名的问题。大家注意下图及连接,不要乱起名。
图片
如果有网站名字问题请看要求:https://help.aliyun.com/zh/icp-filing/user-guide/fill-in-the-website-information-2#title-lhm-b1g-ehx

工信部短信验证

图片
图片

管局审核

这里等就好,我等了1周就好了。不用20多天。

备案成功

备案期间,你的网站会有这样的提醒,是正常的。
图片

备案成功了会有阿里、邮件、短信通知。下图是短信通知。
图片

现在终于可以用https来访问我们的网站了。最后一步是去网络安全备案了。
图片

网络安全备案

https://beian.mps.gov.cn/#/ 我用Edge浏览器不能登录,建议用firefox
图片

选择用户登陆
图片
图片

注册的时候要跳转另外一个网站,并下载APP做扫脸认证
图片

下载APP扫脸认证
图片

注册完账号就可以回到https://beian.mps.gov.cn 新增一个主体
按照步骤一步一步去填写资料就好,这里会要求域名证书,阿里的域名管理里面可以下载,下载好上传上去就好。
图片

网站可以查到备案进度
图片

3个工作日(含提交当天),就收到短信说通过了,非常迅速的。
图片

登录回去网站,就能查到备案编码了。现在是合法合规的网站了,赶紧多点写精彩的文章吧。
图片

Markdown编写

建议使用工具是Yank Note
怎样编写markdown可以参考我的文章这是一篇markdown测试文章

next主题V8内容更新

(1)V8版next修复了一些bug,如侧边栏目录现在可用了。

(2)更强了一些功能,支持Twikoo,还在研究使用中。

(3)hexo g的速度明显慢很多,如果有几百篇文章以上的博主谨慎使用。

安装next8

https://theme-next.js.org/docs/getting-started/ 官方安装方法

下载安装文件方法1(推荐):

https://github.com/next-theme/theme-next-docs 下载源码包,解压出来。
图片

下载安装文件方法2:

1
2
git clone https://github.com/next-theme/theme-next-docs  
# 在hexo文件夹里面下载这个文件

执行安装next8

1
2
cd theme-next-docs  # 进入下载下来的文件夹
npm install # 进行安装

下载配置文件

1
git clone https://github.com/next-theme/hexo-theme-next themes/next # 在hexo文件夹里面下载这个文件

图片
配置启用跟老版next是一样的,见上面的使用next主题美化(7.8.0版)

安装配置Valine(next8)

https://github.com/next-theme/hexo-next-valine 作者的链接

1
2
# 在hexo的文件夹执行这个语句安装valine
npm install next-theme/hexo-next-valine

图片
注册LeanCloud 见上面的评论Valine(Next 7.8.0版)
配置_config.yml,更多配置请看https://valine.js.org/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Valine
# For more information: https://valine.js.org, https://github.com/xCss/Valine
valine:
enable: false #设置为true为开启
appId: # 输入LeanCloud注册的appid
appKey: # 输入LeanCloud注册的appkey
serverURLs: # When the custom domain name is enabled, fill it in here
placeholder: Just go go # comment box placeholder
avatar: mm # gravatar style
meta: [nick, mail, link] # Custom comment header
pageSize: 10 # pagination size
visitor: false # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html
comment_count: true # If false, comment count will only be displayed in post page, not in home page
recordIP: false # Whether to record the commenter IP

部署成功:
图片

(参考)基于Unbuntu22.04(服务端)和Deepin20.9(客户端)的部署hexo

最近尝试了一下,用Ubuntu作为服务端,用Deepin作为客户端。因为CentOS停更了,Windows去中国化了,感觉还是需要有备无患。关于Windows去中国化,可以看本渣的这个帖子:微软这人才更新把中文支持变成屎了,这是微软去中国化了吗?
再加上阿里云续费实在太贵了,见本渣此文章:公有云新增便宜,续费贵的陷阱纯吐槽,本博客今年8月要迁移一次了,当成再练手一次吧。
废话不多说了,开始!

白嫖一下阿里云1个月的2C4G服务器来练手

去到开发者社区>云起实验室>实践系列课>阿里云产品入门第一课,完成第一课的学习,就能白嫖一个月2C4G服务器或或者3个月的券。一个项目的学习,一个月基本足够了。就是不知道能不能无限白嫖。
图片
在ecs的控制台就能找到这个云服务器
图片
轻松应用起来吧,看似一切都没有问题
图片

服务端配置(Ubuntu22.04)

所有操作都在root用户中进行

gcc依赖安装

好像已经默认安装了,看看版本gcc --version

1
2
3
4
5
root@iZ0jl1mlpvfbboaxjs2rp0Z:/usr/local# gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

图片

pcre依赖安装

pcre-config --version查看一下,发现没有安装

1
2
root@iZ0jl1mlpvfbboaxjs2rp0Z:/usr/local# pcre-config --version
Command 'pcre-config' not found, but can be installed with:

Ubuntu建议用这个命令安装pcre

1
2
apt install libpcre3-dev #Ubuntu建议用这个命令安装pcre
root@iZ0jl1mlpvfbboaxjs2rp0Z:/usr/local# apt install libpcre3-dev

再用pcre-config --version查看一下,发现可以返回版本号了。

1
2
root@iZ0jl1mlpvfbboaxjs2rp0Z:~# pcre-config --version
8.39

图片

安装Nginx

1
2
3
4
5
6
7
8
9
10
#安装nginx
cd /usr/local/ --还是到这个目录里面下载文件

#继续下载nginx包到本命令执行的目录,最新是1.25.5了,所以也换到这个版本了
#http://nginx.org/download/在这个网址可以知道最新的包
wget http://nginx.org/download/nginx-1.25.5.tar.gz

tar -xvf nginx-1.25.5.tar.gz #解压包到本命令执行的目录

cd nginx-1.25.5 #解压出来的在nginx-1.25.5目录下,cd进去

图片
在解压出来的目录下执行./configure

1
2
# 确保cd到这个目录: cd /usr/local/nginx-1.25.5
./configure #进行配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#./configure 出来的结果
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

图片

多了Makefile和objs两个文件

继续在/usr/local/nginx-1.25.5目录中执行下面语句

1
2
3
4
make && make install  #进行编译并安装
cd /usr/local/nginx/sbin/ #进入这里启动nginx
./nginx #启动nginx
ps -ef | grep nginx #查看nginx是否在启动

图片
在浏览器上输入服务器的公网IP地址,查看有没有Nginx的返回值,有就证明成功了。
图片

Nginx的启停操作

进入 nginx 目录中: cd /usr/local/nginx/sbin 才能操作

1、查看 nginx 版本号:./nginx -v
图片
2、启动 nginx:./nginx
3、停止nginx:./nginx -s stop
4、重新加载 nginx 重新加载配置文件:./nginx -s reload

无法重启nginx解决方法:80端口被占用

图片

创建hexo网站文件存放的目录

新建/home/www/website文件夹,这是放置静态页面index.htm主页的地方,让nginx代理到这里找到index.htm文件就能浏览网站了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#确保是在root中操作
su root

输入密码 #这里输入密码的时候不会显示*号

cd /home #进入home文件夹

mkdir www #新建www文件夹,小写

cd www #进入www文件夹

mkdir website #新建website文件夹

#修改文件夹权限 这步很重要 视频中没有提及

chmod 777 /home/www/website #授权所有用户组都可以更改

chmod 777 /home/www #授权所有用户组都可以更改

图片

修改nginx.conf

通过vim或vi或xftp命令修改/usr/local/nginx/conf目录下的nginx.conf文件中的这两个地方,换成
root /home/www/website;
当然,如果你的hexo静态网站文件,是在另外一个目录,改成对目录即可。

1
2
3
cd /usr/local/nginx/conf/
cp nginx.conf nginx.conf.backup # 先备份一下nginx.conf文件,以免改错了就芭比Q了
vi nginx.conf #用vi去修改,原来那张用#注释掉

图片

1
2
3
cd /usr/local/nginx/sbin/
./nginx -s reload #修改完conf文件,用这两个命令可以让其生效
netstat -lnpt #查看端口有没有被启用

图片
别忘记,在阿里云的安全组里面也要添加80和443的端口开放
图片

配置nginx脚本

在/etc/init.d/路径下添加脚本文件,名称为nginx,内容如下。用vim或vi添加。

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
#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

图片

1
chmod +x nginx  --继续在在/etc/init.d/路径下,给这个文件赋权

可以使用以下控制指令来使用nginx,而不需要去到/usr/local/nginx/sbin/里面做操作了。
确保在root中操作

1
2
3
4
5
6
service nginx start   --启动
service nginx stop --停止
service nginx reload --重启
ps -ef | grep nginx --查看nginx是否在启动

http://公网IP --可以用来检查nginx有没有启动,有nginx的404错误就是成功启动了

图片

安装Nodejs和npm

1
2
3
4
5
6
#下载并运行Node.js的安装脚本,以在Linux系统中安装Node.js。
curl -sL https://rpm.nodesource.com/setup_10.x | bash -

apt install -y nodejs #利用yum命令来安装nodejs

apt install -y npm #在ubuntu里面,npm要单独安装

图片

1
2
node -v # 查看是否安装成功
npm -v # 查看是否安装成功

图片

安装git,配置权限

下面用Rsync来实现hexo d,所以git配置好像没啥用,但是还是先配置了再说

1
2
3
sudo apt install git-all #在ubuntu上安装git

git --version # 安装完查看git版本,有返回值就成功了

图片

1
2
3
4
5
6
7
chmod 740 /etc/sudoers  #给/etc/sudoers赋权

vi /etc/sudoers #修改/etc/sudoers 当然也可以用xftp来修改,见下图

#加入git ALL=(ALL) ALL 见下图

chmod 400 /etc/sudoers #修改完后,把文件权限改小

图片

配置shh秘钥登录(免密码登录)

在客户端Deepin系统的root用户下操作

在deepin中生成秘钥,执行语句ssh-keygen -t rsa -b 4096

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# root @ N100-PC in ~N100/hexo [21:19:25] 
$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MgOBOCZrRS+4Mw0N/afJec5VfIO2CwzPpDBrU9Dg7+Q root@N100-PC
The key's randomart image is:
+---[RSA 4096]----+
| ooo..o |
|+.=ooo . |
|o=.ooo. . . |
|..+ .=.+ . = o |
|.+ .. &oS o o . |
| o O+* * . |
| . =E. . . |
| o . |
| |
+----[SHA256]-----+

图片
将生成的公钥复制到服务器上的~/.ssh/authorized_keys文件中:

1
2
3
# 在客户端deepin系统执行这个命令
# ssh-copy-id <用户名>@<IP地址>
ssh-copy-id root@8.133.133.223

会自动为服务端上的root用户生成authorized_keys文件
图片

1
2
chmod 600 ~/.ssh/authorized_keys   #给文件赋权
chmod 700 ~/.ssh #给文件夹赋权

图片
在deepin中使用这个语句尝试是否能免密登录

1
2
ssh root@<你云服务器的公网IP>
ssh root@8.130.130.223

图片

创建git空仓库

下面用Rsync来实现hexo d,所以git配置好像没啥用,但是还是先配置了再说

1
2
3
4
5
6
7
8
9
10
11
12
adduser git      #新建一个叫git的linux账号
sudo passwd git #并给git并给这个用户设置密码,牢记这个密码,后面要用

su git #切换到git用户

cd ~ #回到git的home/git目录中

#初始化一个空窗库
git init --bare blog.git ##用这个语句的新建仓库blog.git

#修改这个post-receive文件,把下面那句话插进去。
vi ~/blog.git/hooks/post-receive

把这句话写入post-receive文件

1
git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f
  • /home/www/website 这是放博客静态网站文件的地方
  • /home/git/blog.git 这是放hexo库的地方
    图片

客户端配置(Deepin20.9)

建议所有操作都在root用户中进行,不然容易报错,或者命令上加上sudo

安装git

1
2
3
4
5
6
7
# 安装git 两条语句都行
sudo apt install git-all
sudo apt-get install git-core

git --version # 看版本
node -v # 如果Node是自带的,不用安装。如果没有就看下一小节
npm -v # 看版本

图片

安装nodejs

官方建议安装方法:https://github.com/nodesource/distributions
Node.js v21.x:
Using Ubuntu(因为Deepin是基于Ubuntu魔改的发行版,所以用Ubuntu一样的安装方法)

1
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&\

图片

1
sudo apt-get install -y nodejs

图片

安装hexo

要在root用户下才能成功,这样就导致一般用户无法编辑到初始化的文件了

安装好git和nodejs后就可以运行这一句

1
npm install -g hexo-cli

图片

hexo本地建站

具体操作可查看https://hexo.io/zh-cn/docs/setup

1
2
3
4
5
6
7
8
9
10
11
hexo init <目录所在的文件夹路径> #也可以在要建站的目录下直接运行hexo init
# 方法1 两种方法选其一就行
hexo init /home/N100/hexo/
# 方法2 两种方法选其一就行
cd /home/N100/hexo/
hexo init

cd <刚刚初始化的文件夹> #初始化完成之后,就进去这个文件夹
cd /home/N100/hexo/

npm install #继续执行这个语句来安装npm在这个文件夹里面

本地建站完毕后,就可以看到这些目录,如用tree命令查看一下

1
2
3
4
5
6
7
8
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

简单的hexo命令使用

要在hexo初始化的文件夹里面使用,如我的目录是/home/N100/hexo/,使用hexo命令前要cd到这个目录

1
2
3
4
hexo clean # 把/home/N100/hexo/.deploy_git文件夹清空
hexo g # 建立新的/home/N100/hexo/.deploy_git文件夹,生成新的静态博客网页文件
hexo s # 模拟出本地网站服务,http://localhost:4000/ 用浏览器打卡就可以看到博客最新效果
hexo d # 把/home/N100/hexo/.deploy_git文件夹同步到你配置的服务器地址的对应目录,这个目录会被Nginx代理到公网,就能被访问到了。具体看下面的hexo d教程

安装Rsync来实现hexo d

要在root用户下才能成功

1
npm install hexo-deployer-rsync --save

图片

然后按照下图的方法配置_config.yml,详细见:https://hexo.io/zh-cn/docs/one-command-deployment
图片
我自己的配置如下:
图片

1
2
3
4
5
6
7
8
9
10
11
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: rsync
host: 8.130.130.223
user: root
root: /home/www/website
port: 22
delete: true
verbose: true
ignore_errors: false

然后你就可以尝试hexo d命令了
图片
如果你遇到下面这三个问题,可以这样解决:

hexo d错误1

1
2
# 在/home/N100/hexo/用root用户执行这个语句
npm install --save hexo-deployer-git

图片

hexo d错误2

这个错误应该是用git的deploy方式才会出现,如果用我建议的Rsync方式,不会出现。

1
2
3
git config --global user.email "113191814@qq.com"
git config --global user.name "brian"
# 双引号里面换成你们自己的Email和名称

图片

hexo d错误3

这个错误我是真不知道怎样解决,所以才放弃了用git的deploy方式同步/home/N100/hexo/.deploy_git文件夹,而改成上线建议的Rsync方式。
图片

让非root用户可以修改hexo文件

上面,我们的/home/N100/hexo/里面的文件,都是用root用户去创建的。但是我的Deepin默认登录用户是N100,所以要授权给N100用户可以修改/home/N100/hexo/里面的文件。

1
2
3
4
# 用root用户操作
sudo su
sudo chown -R N100:N100 /home/N100/hexo/
sudo chmod -R 775 /home/N100/hexo/

图片
这样我们就能修改里面的md文件了,平时用hexo new命令的时候,用N100这样的普通用户就行。但是要执行hexo d就要切换到root用户,会比较麻烦。
成功用hexo d基于Rsync方式上传网站文件到阿里云服务器了。可以通过浏览器用IP访问了。
图片

(技巧)Deepin给阿里云传文件SFTP

Deepin是Linux系统,没有xftp,上传文件会比较麻烦。但是Deepin上的FileZilla非常好用,在Deepin商店就能下载。
图片

迁移到腾讯云+CentOS Stream 9

购置腾讯云

因为阿里云续费实在太贵了,故而把本博客迁移到了腾讯云。
图片
经过简单部署完验证后,这2核2G内存3M宽带(200G流量/月)40G存储的资源够用了。而且腾讯云的运维界面比较直观,登录跳转也比较快。
图片

2核2G内存3M宽带(200G流量/月)40G存储暂时看来还是很够用的。
图片

设置防火墙

CentOS Stream 9自带的防火墙默认是没有开启的,这里配置的是腾讯云的防火墙,不是一回事。
图片

配置xshell的免密登录

方便用xshell重免密登录,还有上传文件,编辑文件等。

生成ssh密钥

在轻量云控制台的SSH密钥里面生成一个密钥,其中pem文件只能下载一次,要保留好。如果丢了就只能重新生成新的了。
图片

配置xshell登录

配置一个新的链接,如图:
图片
导入私钥,如图:
图片
尝试链接成功
图片

配置WindTerm免密登录

因为Xshell有版权风险,公司的大神推荐了WindTerm。
这里是下载地址:https://windterm.net/
下载安装都很简单,配置的关键在哪里选择私钥文件。尝试过后发现这些配置,如下图:
图片

SSH免密私钥链接方法

  • 默认进入就是中文,点击【新建会话】就行
  • 选择SSH页签,并填写【主机】的IP,端口默认22,【标签】就是会话名字
  • 在【验证】目录只勾选上尝试公钥认证,如果是通过密码的就选择尝试密码认证,建议只选一种方式。我这里只选择尝试公钥认证,在验证服务器指纹勾选状态下,身份认证文件选择Windows并选择腾讯云服务器给的私钥文件website.pem
  • 在【会话】窗口找到刚刚新建会话,右键选择打开。
  • 弹出的登录窗口,用账户方式登录,并输入登录账号名,如我这里输入了root,点击链接。
  • 如无意外就登录成功了,其他配置都默认就好,我们也不懂怎那样配置。
    图片

SFTP链接

SFTP是默认勾选上的,不需要额外配置
图片
图片

存在问题

  • 容易断开
  • 命令行显示不了中文

dnf更新CentOS Stream 9

root用户中进行

把系统更新到最新,因为CentOS Stream现在定位不是稳定版的系统,所以bug应该会相对更多。但是用于自己搭建博客是够用了,而yum命令切换到dnf命令会更好用。

1
sudo dnf update

安装gcc

root用户中进行

1
2
3
4
# 安装gcc gcc-c++
yum install -y gcc gcc-c++
# RedHat、CentOS、Fedora这三款系统是几乎一样的,都可以用yum命令,其他系统就不行了。
gcc --version # 验证是否安装成功

图片

安装其他依赖

root用户中进行

1
2
# 安装 openssl 、zlib 、 gcc 依赖
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

安装Nginx

root用户中进行

1
2
sudo dnf install nginx  # 使用dnf来安装
nginx -v # 确认是否安装成功

创建hexo网站文件的存放目录

root用户中进行

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /home  #进入home文件夹

mkdir www #新建www文件夹,小写

cd www #进入www文件夹

mkdir website #新建website文件夹

#修改文件夹权限 这步很重要 视频中没有提及

chmod 777 /home/www/website #授权所有用户组都可以更改

chmod 777 /home/www #授权所有用户组都可以更改

配置nginx.conf

在里面加入主页的路径是/home/www/website

root用户中进行

如果是用dnf安装的,就在/etc/nginx/nginx.conf
用二进制文件安装的,参考前面CentOS7的安装方法。
图片

1
2
3
4
5
6
7
# 去到nginx.conf所在目录
cd /etc/nginx
# cp来备份一下nginx.conf
cp nginx.conf nginx.conf.backup
# vim来编辑nginx.conf
vim nginx.conf
# 按照下面的来编辑

只需要分别修改默认配置中的黄色部分即可。
其中如果还没有域名和配置SSL证书的话,443端口部分切勿配置,保持注释状态即可。
图片
图片

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;

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

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /home/www/website;
index index.html index.htm;
}
# root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;
location = /404.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/www/website;
}
}

# Settings for a TLS enabled server.
#
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.brian-zzh.cn;
location / {
root /home/www/website;
index index.html index.htm;
}
# root /usr/share/nginx/html;

ssl_certificate "/etc/ssl/brian-zzh.cn_bundle.crt";
ssl_certificate_key "/etc/ssl/brian-zzh.cn.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;

# # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

}

启动Nginx

root用户中进行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 下面两种方法都一样,那种生效就用那种

sudo systemctl start nginx # 启动
sudo systemctl status nginx # 查看nginx是否在启动
sudo systemctl stop nginx # 关闭
sudo systemctl restart nginx # 重启
sudo systemctl enable nginx # 开机启动
sudo systemctl disable nginx # 禁用开机启动
sudo systemctl is-enabled nginx # 查看是否开机启动
sudo systemctl reload nginx # 重新加载配置

service nginx start # 启动
service nginx stop # 停止
service nginx reload # 重启
ps -ef | grep nginx # 查看nginx是否在启动

#在浏览器中输入服务器的IP,看看能不能返回nginx的错误,能返回错误就证明nginx安装成功了

其中启动nginx的返回结果查看:
图片

安装nodejs(服务端)

root用户中进行

下面是nodejs官网推荐的安装方法

1
2
3
4
dnf module list nodejs # 用来查看能安装哪些nodejs版本
dnf module install nodejs:20/common # 安装20版的common版
node -v # 有版本好返回就是安装成功
npm -v # 有版本好返回就是安装成功

图片

测试存入hexo文件看看能否运行

来到这一步,基本上可以先上传一些html页面去/home/www/website验证一下是否能通过IP进行访问了。
图片
在浏览器输入IP看看能不能浏览到网站页面
图片

如果你没有现成的html文件,让AI给你生成一个简单html代码,然后你用记事本存为index.html文件就行。
图片

腾讯云证书+阿里云域名DNS认证

在腾讯云申请一个SSL证书,如下图
图片
去到阿里云,根据需求配置DNS的解析,来做验证。
图片
在阿里云中添加子域名的指向的服务器,通过ping命令来看是否畅通。
我这里的测试是新建了子域名xt.brian-zzh.cn。 换成brian-zzh.cn也是一样的,在腾讯云证书申请的时候前缀的www留空就是默认是www.brian-zzh.cn一个意思。
图片
因为域名是在阿里云购买的,也是用阿里云的DNS来做跳转,所以证书认证、域名跳IP、域名跳主机名都是在阿里云的DNS里面做配置的。
在阿里云的配置如下图:
(1)腾讯云申请的3个月免费证书解析,CNAME记录类型,按照腾讯云的提示来配置验证。主机记录和记录值,都是由腾讯云提供。
(2)指向腾讯云服务器的解析,A记录类型,主机记录是www,记录值是腾讯云的你购买的轻量云服务器的公网IP
(3)指向腾讯云服务器的解析,A记录类型,主机记录是@,记录值是腾讯云的你购买的轻量云服务器的公网IP
图片
而证书是在腾讯云申请的3个月免费的,现在的免费证书都只有3个月了。也就是每3个月就要手动换一次了。更换操作是:
(1)去腾讯云申请新SSL证书
(2)去阿里云DNS认证解析证书
(3)下载通过认证的腾讯云SSL证书
(4)解压到腾讯云服务器的etc/ssl文件夹里面,替换旧的证书

配置Nginx.conf文件来实现域名访问

在腾讯云下载Nginx用的证书文件
图片
把解压出来的4个文件放到服务器的etc/ssl文件夹里面
图片
Nginx的配置确保/etc/nginx/nginx.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;

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

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /home/www/website;
index index.html index.htm;
}
# root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;
location = /404.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/www/website;
}
}

# Settings for a TLS enabled server.
#
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.brian-zzh.cn;
location / {
root /home/www/website;
index index.html index.htm;
}
# root /usr/share/nginx/html;

ssl_certificate "/etc/ssl/brian-zzh.cn_bundle.crt";
ssl_certificate_key "/etc/ssl/brian-zzh.cn.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;

# # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

}

通过域名访问,可以查看证书是否也存在。
图片

遇到nginx启动失败处理方法:

一般是nginx.conf配置的错误
图片

安装git(服务端)

root用户中进行

1
2
# 用官方的方法安装git
sudo dnf install git-all
1
2
3
4
5
6
7
chmod 740 /etc/sudoers  #给/etc/sudoers赋权

vim /etc/sudoers #修改/etc/sudoers 当然也可以用xftp来修改,见下图

#加入
git ALL=(ALL) ALL
#见下图

图片

1
chmod 400 /etc/sudoers  #修改完后,把文件权限改小

配置密钥,让Windows免密登录云服务器

root用户中进行

这个配置是为了让hexo中利用git仓库同步功能来同步本地的静态网页文件到服务器的指定目录

1
2
3
4
adduser git      #新建一个叫git的linux账号
sudo passwd git #并给git并给这个用户设置密码,牢记这个密码,后面要用

su git #切换到git用户

git用户中进行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd ~    #去到git用户的主目录/home/git

mkdir .ssh #创建一个.ssh的隐藏文件夹

cd .ssh #进入这个文件夹

vim authorized_keys
#创建一个authorized_keys的文件,文件名千万别打错
#把windows的登录用户中的C:\Users\{用户名}\.ssh 下面的 id_rsa.pub的内容复制出来,
#放在authorized_keys文件中,当然用xftp放也行。
#如果没有找到windows的id_rsa.pub文件,
#在本地电脑打开powerShell,创建密钥。创建密钥的命令是
ssh-keygen -t rsa
#如果你已经有了密钥就不用再次创建了。

把windows的登录用户中的C:\Users{用户名}.ssh 下面的 id_rsa.pub的内容复制出来,放在/home/git/.ssh目录中的authorized_keys文件中,当然用xftp放也行。
图片

1
2
3
#继续实使用git用户操作
chmod 600 ~/.ssh/authorized_keys #给文件赋权
chmod 700 ~/.ssh #给文件夹赋权

配置好后,在windows的powershell用ssh -v {linux用户名}@{linux公网IP} 来尝试连上服务器

1
2
#如
ssh -v git@124.222.51.211

图片

报错解决01-无法用ssh连上或每次都需要输入密码

如果报如下错误了,应该是git对文件权限不够,尝试下面的解决方式。
(1)删除C:\Users\Brian.ssh下面的known_hosts和known_hosts.old两个文件
(2)给服务器重的authorized_keys文件和目录~/.ssh授权
图片

1
2
3
#继续使用git用户操作
[git@VM-4-16-centos .ssh]$ chmod 700 ~/.ssh
[git@VM-4-16-centos .ssh]$ chmod 600 ~/.ssh/authorized_keys

成功了就能下一步了
图片

创建git空仓库(服务端)

git用户中进行

1
2
3
4
cd ~  #回到git的home/git目录中

#初始化一个空窗库
git init --bare blog.git

图片

1
2
3
4
5
#去到这个目录
cd /home/git/blog.git/hooks/

#创建post-update文件
vim post-update

把这句话写入post-update文件

1
git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f
  • /home/www/website 这是放博客静态网站文件的地方
  • /home/git/blog.git 这是放hexo库的地方
    图片

配置hexo的_config.yml(客户端)

1
2
3
4
5
# 配置_config.yml
deploy:
type: git
repo: git@124.222.51.211:/home/git/blog.git
branch: master

图片

测试通过hexo d发布成功

图片

遇到问题01-hexo d无法同步文件

配置过程中遇到了这个问题:在执行hexo d命令的时候没有任何报错,就是文件同步不过去服务器。
解决思路:
(1)备份hexo里面的三个文件夹/文件夹
图片
(2)删除hexo里面的所有文件
(3)安装最新的git和nodejs,都是基于windows的
Git:https://registry.npmmirror.com/-/binary/git-for-windows/v2.45.2.windows.1/Git-2.45.2-32-bit.exe
nodejs:https://nodejs.org/zh-cn/download/prebuilt-installer
(4)重新安装hexo,在hexo文件夹中执行open git bash here。在C:\blog\HEXO中执行,这个目录就是hexo初始化所有在的目录,也是存hexo全部文件的目录。每次进行命令操作都只能在这个个文件夹中使用open git bash here。
图片

1
2
3
4
5
6
7
8
npm install -g hexo-cli
# 重新安装hexo,发现有更新。
# 继续在hexo文件夹中执行,初始化hexo
hexo init
# 再执行安装npm
npm install
# 再执行安装hexo-deployer-git
npm install hexo-deployer-git --save

(5)把备份的三个文件,还原回到C:\blog\HEXO中
图片

1
2
3
4
# 执行尝试能否hexo d可用,下面3句命令依次执行
hexo clean
hexo g
hexo d # 我在这里出问题了,接续下一步,重装服务端上的git仓库

如果还不行,继续尝试重建服务器中的git仓库
(6)删除服务器中,/home/git目录下的blog.git

git用户中进行

1
2
cd /home/ 
rm -fr git/* #删除仓库blog.git

(7)继续重复上一步创建空仓库的操作。最终解决了hexo d不报错但是不能同步文件的问题。

腾讯云重新备案问题

因为网络设备从阿里云换成腾讯云,ICP需要重新备案,不然站用http无法访问了。

腾讯的备案真实太烂了,只能用电话,被所有运营商都拦截了电话,根本接不到电话。人家阿里都用钉钉了,你用微信或QQ会死人吗?

图片
图片
只有一个手机是无法成功备案的,垃圾腾讯,垃圾政策,强迫人无止尽的开电话号码,为了救运营商是真不要脸了。
图片

已经关了高频拦截,腾讯的电话还是打不进来

图片
图片
图片

最后还是接了别人的手机号码来做认证

  • 主手机:会问你的认证域名和身份证号
  • 紧急联系手机:会问备案人的全名

终于去到工信部的验证了,在提供的网址输入验证码、主手机号、身份证号就能验证成功,继续等通知就好。

图片

图片

大概7天就会验证通过,备案号会+1,所以现在就变成粤ICP备2023100809号-1了。

接着还要去公安部继续备案,因为之前主体和网站都备案过了,只需要做变更改IP和上存新的域名证书就好了,所以备案号是不会变的。具体可以看第五大点的【5. 网络安全备案】

记得修改就好C:\你的路径\HEXO\themes\next_config.yml

图片

利用cerbot自动部署ssl证书

最近腾讯云一直催我ssl证书到期了,B站大佬教了我一个自动申请和部署的方法,就试试看了。想不到成功了。

图片

安装epel

1
2
sudo su # 必须要在root用户中操作
yum install -y epel-release # 安装以来

图片
图片

安装certbot

1
2
3
4
5
[root@VM-4-16-centos lighthouse]# yum install -y certbot
[root@VM-4-16-centos lighthouse]# certbot --version
certbot 2.11.0
[root@VM-4-16-centos lighthouse]# which certbot
/bin/certbot

图片
图片

申请证书并做DNS认证

执行语句certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns --email 113191814@qq.com --agree-tos -d *.brian-zzh.cn
其中113191814@qq.com改成你自己的Email地址
其中*.brian-zzh.cn改成你自己的域名
如果你是首次申请,需要输入y来确认邮箱注册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[lighthouse@VM-4-16-centos ~]$ sudo su
[root@VM-4-16-centos lighthouse]# certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns --email 113191814@qq.com --agree-tos -d *.brian-zzh.cn
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for *.brian-zzh.cn

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.brian-zzh.cn.

with the following value:

6SQg2NHHysHrur72nq2d6J_4-AqlYlHg4sbhssJ_Jls

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.brian-zzh.cn.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

来到这一步,需要去域名提供商里面做txt的dns认证,我用的是阿里云。填写的方法如下图:

图片

接着点【回车】继续下一步。看到Successfully就是成功了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/brian-zzh.cn/fullchain.pem
Key is saved at: /etc/letsencrypt/live/brian-zzh.cn/privkey.pem
This certificate expires on 2024-12-17.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

去到/etc/letsencrypt/live/brian-zzh.cn/就能找到申请下来的证书文件了

1
2
3
[root@VM-4-16-centos lighthouse]# cd /etc/letsencrypt/live/brian-zzh.cn/
[root@VM-4-16-centos brian-zzh.cn]# ls
cert.pem chain.pem fullchain.pem privkey.pem README

配置nginx.conf的新证书位置

修改/etc/nginx/nginx.conf文件中的ssl证书位置,修改的地方如图所示:

图片

具体操作如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 备份一下nginx.conf文件
[root@VM-4-16-centos nginx]# cp nginx.conf nginx.conf.backup.20240918
[root@VM-4-16-centos nginx]# ls
conf.d fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf nginx.conf.backup.20240918 scgi_params uwsgi_params win-utf
default.d fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.backup nginx.conf.default scgi_params.default uwsgi_params.default
# 修改nginx.conf文件
[root@VM-4-16-centos nginx]# vim nginx.conf
# 重新加载nginx.conf文件
[root@VM-4-16-centos nginx]# systemctl reload nginx
[root@VM-4-16-centos nginx]# ps -ef | grep nginx
root 5071 1 0 Jun24 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 4123986 5071 0 20:31 ? 00:00:00 nginx: worker process
nginx 4123987 5071 0 20:31 ? 00:00:00 nginx: worker process
root 4124113 4113450 0 20:32 pts/0 00:00:00 grep --color=auto nginx

图片

访问https域名确认证书成功

通过访问https://www.brian-zzh.cn/ 查看证书是否成功。

图片

在手机浏览器上这个证书还是会报错?其实是来自网站的内容分析,被标记为广告网站了,我也想有广告收入,报错的VIVO是不是给我投一个?🤣

图片

自动证书续期(测试不能用)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 通过这个命令可以续期,经过测试是要配置腾讯云DNS解析的API,看起来很复杂就没有去研究了。
[root@VM-4-16-centos ~]# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/brian-zzh.cn.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Failed to renew certificate brian-zzh.cn with error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.')

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
/etc/letsencrypt/live/brian-zzh.cn/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

手动证书续期(可以用)

自动更新证书续期,需要调用API去改DNS做认证,这个配置不会,还是手动吧。
继续执行申请证书的语句

1
certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns --email 113191814@qq.com --agree-tos -d *.brian-zzh.cn

获得了如图的值,去腾讯云的域名解析上做一个解析,因为之前配置过一次了,修改以下记录值就行了。等1分钟后,回到命令行点一下回车。
图片

返回的信息带有Successfully就是成功了。
进去存放证书的目录看看,pem文件也是最新的日期。
继续执行reload一下nginx,就可以刷新一下网站,发现证书续期成功呢了。操作还是比纯在腾讯云手工申请、手工认证、手工下载、手工更新证书文件这一套下来快很多的。

1
systemctl reload nginx

图片

腾讯云官方cerbot用法

没有测试过,等下次换证书的时候折腾一下。感觉是需要用腾讯的收费证书才行。
https://cloud.tencent.com/document/product/302/105900

域名从阿里云迁到腾讯云

霸道的阿里云,他们家的域名只能用在自己的云服务器上。一气之下就迁出了算了。

图片

在阿里云上申请一个迁出码

图片

阿里云会发一个邮件告诉你迁出码,这个码在腾讯云中输入

图片

然后在腾讯云中给钱就好了。
PS:如果之前还没有做实名认证的话,要先做实名认证【信息模板】

图片

记得在阿里云中选择【马上转出】,会收到一封邮件,然后点击链接确认马上转出就好。一般30分钟就完成转出,腾讯云也会收到转入。

图片

在腾讯云中完成DNS的域名解析配置,让域名可以转到去你的腾讯云服务器。

图片

工信部也发来了备案更新的通知,应该是不用再去更新备案了吧?
过了几天了,网站还能正常访问。域名所有人没有变,服务器没有变,IP地址没有变,只是域名服务商变成腾讯云了,应该不用去申报啥的。

图片

重启腾讯云服务器

因为在1Panel上手贱安装了Only Office的Docker版,直接就把腾讯云服务器搞崩了。正好练练手重启,之前一次都没有重启过。
因为服务器太卡了,最终是等了5分钟后,腾讯云才执行的强制重启。
图片

因为腾讯云上安装了有

  • hexo
    • git
    • nginx (需要手工启动)
    • nodejs
  • Docker
    • 思源笔记(docker)
  • 1Panel (会自动启动)
    • frps(内网穿透服务端 docker)
    • Only Office(docker)

需要手工启动的有nginx
图片

需要在1Panel中手工启动的有Docker自身服务、思源笔记服务(docker)。其中OnlyOffice服务(docker)和frps(docker)因为是通过1Panel安装的,会在1Panel启动Docker时候一同启动,应该是1Panel自己配置的compose了。

最后重启完腾讯云,OnlyOffice服务也启动起来了,占了1个G内存,CPU也占了1个核的99%。能用,但是没有必要,2C2G的服务器来说太勉强了。
图片
图片
图片

利用acme.sh自动部署ssl证书

安装acme.sh(中国版)

先切换到root用户

1
2
[lighthouse@VM-4-16-centos ~]$ sudo -i
[root@VM-4-16-centos ~]#

克隆中国gitee仓库的acme.sh

1
git clone https://gitee.com/neilpang/acme.sh.git

图片
cd进去/root/acme.sh目录,看到有内容就证明克隆成功了

1
cd acme.sh

图片

1
2
3
4
5
6
7
# 安装acme.sh
# ./acme.sh --install -m my@example.com
./acme.sh --install -m hezhiheng111@163.com
# 执行source ~/.bashrc来从新加载环境
source ~/.bashrc
# 测试是否安装成功,用help看看有没有命令返回
acme.sh -h

图片

申请证书DNSPod腾讯云

前提1:先要保证你的Email注册过zerossl的账号,如果没有注册过就这样解决。

1
2
3
4
5
root@DESKTOP-FH09R9R ~/.acme.sh # acme.sh --register-account -m hezhiheng111@163.com --server zerossl
[Tue Apr 22 09:00:25 CST 2025] Registering account: https://acme.zerossl.com/v2/DV90
[Tue Apr 22 09:01:52 CST 2025] Registered
[Tue Apr 22 09:01:52 CST 2025] ACCOUNT_THUMBPRINT='这里会返回一串数字字符'
# 这就证明成功注册了

图片
⚠️不然会出现如下报错
图片

前提2:在你的腾讯云上开通DNSPod Token
开通地址是:https://console.dnspod.cn/account/token/token
确保你的域名brian-zzh.cn是在腾讯云购买,并且已经指向去你的腾讯云服务器。
图片
把获得的ID和KEY写入~/.acme.sh/account.conf
图片

1
2
3
4
5
6
7
8
# 进入~/.acme.sh/目录
cd ~/.acme.sh/
# 看看里面有什么,找到account.conf
ls -lh
# 编辑account.conf,写入DNSPod的ID和KEY
vim account.conf
# 检查account.conf有没有写入成功
cat account.conf
1
2
export DP_Id="你的ID"
export DP_Key="你的Key"

⚠️不然会出现如下报错
图片

通过命令来申请证书

1
2
3
acme.sh --issue --dns dns_dp -d brian-zzh.cn -d *.brian-zzh.cn
# 如果报错了,就最后面加--debug来获得日志,粘贴给DeepSeek来看看是什么问题。
# acme.sh --issue --dns dns_dp -d brian-zzh.cn -d *.brian-zzh.cn --debug

有这样的返回值就是成功了
图片
进去目录看看是否文件申请下来了

1
2
3
root@DESKTOP-FH09R9R ~/.acme.sh # cd brian-zzh.cn/
root@DESKTOP-FH09R9R ~/.acme.sh/brian-zzh.cn # ls
brian-zzh.cn.cer brian-zzh.cn.conf brian-zzh.cn.csr brian-zzh.cn.csr.conf brian-zzh.cn.key ca.cer fullchain.cer

配置Nginx

前提:确保/etc/nginx/nginx.conf中SSL证书配置跟acme.sh --install-cert的配置是一样的
图片

1
2
3
4
acme.sh --install-cert -d brian-zzh.cn \
--key-file /etc/ssl/brian-zzh.cn.key \
--fullchain-file /etc/ssl/brian-zzh.cn.crt \
--reloadcmd "service nginx force-reload"

到浏览器刷新一下页面,看看证书有没有更新。有更新就是成功了。
图片

其他操作

通过crontab -l命令查看cron有没有在运行,这是自动续期证书的任务。

1
2
3
4
[root@VM-4-16-centos ssl]# crontab -l
*/5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &'
43 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
# 如无以外,每60天这里的两个程序就会给你更新SSL证书。本渣7月份查看后看看是否成功。

通过acme.sh --list命令可以查看证书申请的情况

1
2
3
acme.sh --list
Main_Domain KeyLength SAN_Domains CA Created Renew
brian-zzh.cn "2048" *.brian-zzh.cn ZeroSSL.com 2025-04-22T01:51:46Z 2025-06-21T01:51:46Z