hexo+next+阿里云Ubuntu 22.04建站相关配置

环境:hexo+next主题+阿里云ubuntu 22.04,本篇文章主要是记录在部署过程中遇到的一些在hexo和next教程中没有详细说明的情况,希望对大家有所帮助。

iterm2上设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
# 设置代理
export http_proxy=http://127.0.0.1:7890
export https_proxy=$http_proxy
# 安装oh my zhs
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 取消代理
unset http_proxy https_proxy

# 你可以把它们写在 ~/.zshrc 或者 ~/.bash_profile中,随时切换
vim ~/.zshrc
alias goproxy='export http_proxy=http://127.0.0.1:7890 https_proxy=http_proxy'
alias disproxy='unset http_proxy https_proxy'
source ~/.zshrc

给oh my zsh安装代理插件
zsh-proxy代理插件

Mac上开代理的情况下使用npm命令

vim /user/xia0sheng/.npmrc

1
2
3
4
5
proxy = http://127.0.0.1:7890/
https_proxy = http://127.0.0.1:7890/
strict-ssl = false
ca = false
registry = https://registry.npmmirror.com/

next darkmode主题不生效

原因是macbook本身没有开启深色模式

ubuntu 22.04相关配置

Initial Server Setup with Ubuntu 22.04

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
apt update -y
apt upgrade -y

apt install git
git config --global user.name "xia0sheng"
git config --global user.email "wangyouyu6@163.com"
git config --global init.defaultBranch main

apt install nginx
systemctl start nginx
systemctl enable nginx

adduer git
usermod -aG sudo git
su git

sudo mkdir -p /var/www/hexo
sudo chown -R $USER:$USER /var/www/hexo
sudo chmod -R 755 /var/www/hexo

sudo mkdir repos && cd repos
sudo git init --bare hexo.git

sudo vim post-receive

#!/bin/sh
git --work-tree=/var/www/hexo --git-dir=/var/www/repos/blog.git checkout -f

sudo chmod +x post-receive

sudo git init --bare /var/www/repos/hexo.git

su -
chown -R git:git /var/www/repos/hexo.git/

vim /var/www/repos/hexo.git/hooks/post-receive
#!/bin/sh
git --work-tree=/var/www/hexo --git-dir=/var/www/repos/hexo.git checkout -f

chmod +x /var/www/repos/hexo.git/hooks/post-receive

ssh-copy-id -i ~/.ssh/id_rsa.pub git@wangyouyu.com # 建立信任关系

ssh git@wangyouyu.com # 试一下能不能登录

修改_config.yml

1
2
3
4
5
6
7
8
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
- type: git
repo:
github: git@github.com:xia0sheng/blog,main
aliyun: git@wangyouyu.com:/var/www/repos/hexo.git,main
- type: leancloud_counter_security_sync

提交部署

1
hexo clean && hexo g && hexo d

关于busuanzi不能正确统计uv和pv的问题

如果域名不是https,那么busuanzi统计会有问题,pv和uv同时增加

网站添加ssl证书

官方教程:certbot自动添加证书并更新
digitalocean教程:How To Secure Nginx with Let’s Encrypt on Ubuntu 20.04

希望带和不带www的域名都指向 https://wangyouyu.com

Issue with non www and www redirect to www with https in Nginx

Goal: to redirect each of the 3 non-https://@ options into one secure @. In other words, http://www.example.com, http://example.com, https://www.example.com should ALL redirect to https://example.com – but without the IF’s.

https://www.digitalocean.com/community/questions/issue-with-non-www-and-www-redirect-to-www-with-https-in-nginx

Remove example.com from server_name directive and create a new server block

最终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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

server {

root /var/www/hexo;

index index.html index.htm index.nginx-debian.html;

server_name wangyouyu.com;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/wangyouyu.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/wangyouyu.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {
listen 443;
listen [::]:443 ipv6only=on;
server_name www.wangyouyu.com;
ssl_certificate /etc/letsencrypt/live/wangyouyu.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/wangyouyu.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
return 301 https://wangyouyu.com$request_uri;

}

server {
if ($host = www.wangyouyu.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = wangyouyu.com) {
return 301 https://$host$request_uri;
} # managed by Certbot



server_name wangyouyu.com www.wangyouyu.com;
listen 80;
return 404; # managed by Certbot


}

证书部署测试

https://www.ssllabs.com/ssltest/

测试网址,都指向https://wangyouyu.com就对了

wangyouyu.com
www.wangyouyu.com
https://wangyouyu.com
https://www.wangyouyu.com

Hexo设置 read more 即“阅读全文”

在文章正文摘要部分后面插入 <!-- more -->

disqusjs 基础模式不显示的问题

EBCE5EF30E99DEE942EFF5826D548F56

解决:[Disqus API Application] 里website里填写的域名为http开头,改为https就可以了