本博客 Nginx 配置之完整篇

最近有很多朋友邮件或者留言询问本博客服务端配置相关问题,基本都是关于 HTTPS 和 HTTP/2 的,其实我的 Nginx 配置在之前的文章中多次提到过,不过都比较分散。为了方便大家参考,本文贴出完整配置。

本文内容会随时调整和更新,请不要把本文内容全文转载到第三方平台,以免给他人造成困扰或误导。另外限于篇幅,本文不对配置做过多说明,如有疑问或不同意见,欢迎留言讨论。

本博客最新的 Nginx 配置,见这篇文章:本博客开始支持 TLS 1.3

不教而杀谓之虐 不戒视成谓之暴 慢令致期谓之贼

不懂得如何教化孩子,而一昧禁绝,是为虐待者。
不花时间和心思与孩子沟通,而只求成绩,是为暴徒。
孩子童年时,对其忽视懈怠,长大后却临时抱佛脚,急于求成,是为贼人。
千年过去,孔子的话,依然使我们警醒。

你可以喜欢,你可以揣摩心思,但你不能偷窥。这不仅仅是心理问题。也是不尊重他人。你要承受所带来的后果。也要远离。这是你做错了。你不该这样。钱,其他的也带不来你的欢乐。你也不应该去找寻她了。

发条橙和西部世界

电影里,阿历克斯的父母,只给他中产阶级的生活,其余一切漠不关心。现实中,我偶然看湖南卫视,《变形记》的一幕:一个少年对母亲吼道“滚你妈的”。后来才得知,这位母亲离婚很久,却没把真相告诉儿子。你不尊重我的知情权,还想让我尊重你?《网瘾之戒》的结尾,柴静向“问题少年”的父母们,提出了一些问题——

作者:罗罔极
链接:https://zhuanlan.zhihu.com/p/30386257

开源软件镜像站

清华大学开源软件镜像站-CentOS7.md

CentOS-Base.repo

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
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

epel.repo

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
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

rpmforge.repo

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
cat > /etc/yum.repos.d/rpmforge.repo << EOF
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

[rpmforge-extras]
name = RHEL $releasever - RPMforge.net - extras
baseurl = https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/extras
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-extras
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

[rpmforge-testing]
name = RHEL $releasever - RPMforge.net - testing
baseurl = https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/testing
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-testing
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
EOF

使用 Travis CI 自动部署 Hexo 博客

安装 hexo

1
2
3
4
nvm install 8.9.1
npm install hexo-cli -g

hexo version

生成 sshkey

1
2
3
ssh-keygen -t rsa -b 4096 -C "ovwane@gmail.com" -f ~/.ssh/hexo_rsa

#github和coding.net都是设置的只有这个项目可以使用这个公钥
1
2
3
4
5
6
7
8
9
10
11
12
vim ~/.ssh/config
# github.com
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/hexo_rsa

# git.coding.net
Host git.coding.net
HostName git.coding.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/hexo_rsa

测试

1
2
ssh -T git@github.com
ssh -T git@git.coding.net

初始化blog分支

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cd ~/projects

hexo init blog.ovwane.me
cd blog.ovwane.me
npm install

初始化git
git clone -b hexo git@github.com:ovwane/ovwane.github.io.git blog.ovwane.me
git init
git checkout -b hexo
git submodule add https://github.com/ovwane/hexo-theme-spfk.git themes/spfk

git add .
git commit -m "初始化hexo分支"
git remote add origin git@github.com:ovwane/ovwane.github.io.git

git push origin hexo

更改主题为spfk

1
2
3
4
5
6
7
cd ~/projects/blog.ovwane.me
rm -rf themes/landscape
#sed -i 's/theme: landscape/theme: spfk/g' _config.yml

git add .
git commit -m "删除默认主题landscape,然后修改主题为spfk"
git push origin hexo

修改_config.yml 和 主题的 _config.yml替换主题的图片

配置travis

1
2
3
4
5
6
7
cd ~/projects/blog.ovwane.me
mkdir .travis
touch .travis.yml
brew install travis
travis login --auto
travis encrypt-file ~/.ssh/hexo_rsa --add
mv hexo_rsa.enc .travis/

.travis/ssh_config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vim .travis/ssh_config
# github.com
Host github.com
HostName github.com
User git
StrictHostKeyChecking no
IdentityFile ~/.ssh/hexo_rsa
IdentitiesOnly yes

# git.coding.net
Host git.coding.net
HostName git.coding.net
User git
StrictHostKeyChecking no
IdentityFile ~/.ssh/hexo_rsa
IdentitiesOnly yes
1
2
3
4
cd ~/projects/blog.ovwane.me
git add .
git commit -m "添加travis ci相关文件"
git push origin hexo
1
2
3
4
5
6
7
8
9
10
11
12
13
vim _config.yml
title: 幻舞梦境
author: 幻舞梦境
url: http://ovwane.me
skip_render:
- README.md

deploy:
type: git
repo:
github: git@github.com:ovwane/ovwane.github.io.git
coding: git@git.coding.net:ovwane/ovwane.coding.me.git
branch: master
1
2
3
4
cd ~/projects/blog.ovwane.me
git add .
git commit -m "修改_config.yml添加deploy信息"
git push origin hexo

.travis.yml

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
language: node_js
sudo: false
node_js:
- 8.9.1
branches:
only:
- hexo
cache:
apt: true
yarn: true
directories:
- node_modules
before_install:
- openssl aes-256-cbc -K $encrypted_b6a9c7fbd133_key -iv $encrypted_b6a9c7fbd133_iv -in .travis/hexo_rsa.enc -out ~/.ssh/hexo_rsa -d
- chmod 600 ~/.ssh/hexo_rsa
- eval $(ssh-agent)
- ssh-add ~/.ssh/hexo_rsa
- cp .travis/ssh_config ~/.ssh/config
- git config --global user.name "Jinlong Quan"
- git config --global user.email "ovwane@gmail.com"
install:
- npm install hexo-cli -g
- npm install hexo-deployer-git --save
- npm install
- git clone https://github.com/ovwane/ovwane.github.io .deploy_git
- cd .deploy_git && git checkout master
- cd ..
script:
- hexo clean
- hexo generate
- hexo deploy
after_success:
- echo "OK!网站部署成功啦!"
1
2
3
4
cd ~/projects/blog.ovwane.me
git add .
git commit -m "添加.travis.yml打包命令"
git push origin hexo
1
2
3
- git clone https://github.com/ovwane/ovwane.github.io .deploy_git
- cd .deploy_git && git checkout master
- cd ..
1
2
3
4
cd ~/projects/blog.ovwane.me
git add .
git commit -m "添加.travis.yml打包命令,并添加拉取master分支,防止每次更新全部文件。"
git push origin hexo

参考

使用 Travis CI 自動發布 Hexo 內容到 Github
使用Travis CI自动构建hexo博客
使用Travis CI自动部署Github/Coding Pages博客
#232 Hexo + GitHub + Travis CI + VPS 自动部署
用 Travis CI 自動部屬 hexo 到 GitHub
用 Travis CI 自动部署 hexo
使用 Travis CI 持续构建 Hexo

连排版都不好,谁看你内容啊!

目录结构清晰

标题一般3级就没有了。4级标题很少见。

,