blog搭建
刚搭起来,趁着热乎劲,做个记录.
记得,从开始打算搭建自己的博客那一刻起,你就是这个网站的cto了。
- 注册域名,购买云主机(管局备案)
- 域名添加dns解析,a地址到云主机提供的外网ip
- 云主机设置
- ssh登陆:
- 下载安装 openresty
- 修改or配置文件 & 新建一个server的配置文件
- 下载 certbot,生成证书。 配置到 新建的or server配置文件中
- hugo 安装
- 下载git,添加 ssh-key到 github
- 挑选hugo主题,下载到theme文件夹
- 本机安装hugo + 下载主题。调试+写文
- rsync public文件夹到远程主机
details
ssh 登陆
下载云主机秘钥到本机;
ssh -i 本机路径/秘钥 root@云主机外网ip
还可以参考云主机相关帮助文档
安装openresty 并配置
- 安装文档 有详细linux系统安装命令,登陆云主机依葫芦画瓢执行即可
- 安装完毕查看
ubuntu@VM-4-5-ubuntu:~$ openresty -v
nginx version: openresty/1.19.3.1
openresty -V (大写) 可查看编译的支持的模块,和一些已经设置的默认配置值: --prefix=/usr/local/openresty/nginx
ubuntu@VM-4-5-ubuntu:~$ sudo openresty 启动or,就可以在浏览器访问了域名了。 一切正常就是默认的 or欢迎页
- 修改配置文件
ubuntu@VM-4-5-ubuntu:~$ mkdir or_conf // 新建一个我们自己的server配置文件
ubuntu@VM-4-5-ubuntu:~$ cd or_conf
ubuntu@VM-4-5-ubuntu:~/or_conf$ touch myserver.conf
ubuntu@VM-4-5-ubuntu:~$ sudo vi /usr/local/openresty/nginx/conf/nginx.conf
- 启用user,并改为root.不然后续访问文件等,启动的worker进程可能权限问题。有403的error : forbidden (13: Permission denied)
#user nobody; ==> user root;
- http 块最后添加我们server配置的引用
include /home/ubuntu/or_conf/*.conf;
- 注释掉server
- 关闭,保存
- 修改 myserver.conf
ubuntu@VM-4-5-ubuntu:~/or_conf$ vi myserver.conf
以域名 abc.com为例
server {
listen 80 default;
server_name abc.com;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("this is helloworld test")
}
}
}
- 测试一下
ubuntu@VM-4-5-ubuntu:~/or_conf$ sudo openresty -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
再浏览器访问,正确响应就是我们的"this is helloworld test" // 浏览器可能会有缓存,记得清除
使用certbot生成证书 和 配置https
先关闭nginx: sudo openresty -s stop
- 安装certbot
ubuntu@VM-4-5-ubuntu:~$ sudo apt install certbot
- 获取证书
以 域名 abc.com 为例
ubuntu@VM-4-5-ubuntu:~$ sudo certbot certonly --manual -d "abc.com" -d "*.abc.com"--preferred-challenges dns
- certonly 只为域名申请证书
- --manual 不使用certbot的若干插件
- -d: 证书申请域名。可指定多个
- --preferred-challenges 优先使用域名所有权的校验方式。可设置参数值:http/dns (后续需要使用) http 需要再web根目录下/.well-known/acme-challenge/ 放置指定文件供访问; dns 需要配置dns解析 以 _acme-challenge 开头的文件值。
执行了命令后,会有交互操作:
- 填邮箱地址。 (符合邮件格式即可)
- 同意
- 确认信息鸭
- 生成了一个 dns的 TXT解析记录。 到这一步后,需要把 解析记录填到你的域名解析里。
- 在dns 解析中增加 _acme-challenge.abc.com 值为certbot生成的
- 本地机器(或者另一个终端) 使用命令查看是否生效 nslookup -q=txt _acme-challenge.abc.com
- 最后生成证书。目录 /etc/letsencrypt/live/abc.com/
查看证书
ubuntu@VM-4-5-ubuntu:~$ sudo certbot certificates
运行后会打印:
- 证书名
- 证书包含域名
- 过期时间啊
- 路径 等等等
证书续期 重新运行创建证书命令,会根据已经存在证书自动renew 重复更新 dns解析 txt文档值 (再新建一下,填入新生成字符串)
ubuntu@VM-4-5-ubuntu:~$ sudo certbot certonly --manual -d "abc.com" -d "*.abc.com"--preferred-challenges dns
-----不要----- ubuntu@VM-4-5-ubuntu:~$ sudo certbot renew --cert-name xxxx.com
- --cert-name 指定续期的证书名。查看证书中打印的Certificate Name: 证书更新成功 提示
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/你的域名/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/你的域名/privkey.pem
Your cert will expire on 新-的-时间. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
最后需要nginx reload
其他证书相关管理,添加域名啊,强制更新啊之类的操作可参看certbot 官方文档
- 配置or https
server {
listen 443 ssl;
server_name abc.com;
# 填 刚申请域名的证书路径(比如:abc.com)
ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/abc.com/privkey.pem;
}
server {
listen 80 default;
server_name abc.com;
return 301 https://abc.com$request_uri;
}
云主机上ssh-key 配置到 github
在云主机上使用 ssh-keygen 生成 SSH key
ssh-keygen -o -t rsa -C "email@example.com" //一路enter, 生成密钥文件目录: /home/xxxxx/.ssh/
-o 强制生成 OpenSSH格式 key
-t 设置 SSH-key 类型
-C 添加邮件为metadata做备注, 添加到public key文件的末尾
登陆github, setting -- SSH and GPG keyss -- New SSH key, 复制已经生成的 .ssh/id_rsa.pub文件内容即可
rsync 同步
rsync -av source/ username@remote_host:destination
这篇rsync教程讲的清楚详细,可参看
last
以上, 有错误的地方或者任何疑问,请联系 email
// comment
/*
another
markdown 格式测试
*/
func Test(name string) bool {
if name == "hello" {
return true
}
return false
}
首先得确定下大概怎么干这件事。随便一搜有很多的方案,当然有更多的教程。囫囵个大概。
本着满足核心需求即可,选, nginx + hugo(nginx做web服务,hugo来生成静态页面文件。)
nginx:有了解的基础。方便支持https。无需开发就完全cover响应静态页面的web
讲道理,生成静态页面,很多框架都可以。hexo,hugo。。。。此处如果有熟悉的,选熟悉的更好。 选hugo,一来较新go语言开发(假想自己以后可以追源码)。二来,轻简,当然官网上可选主题大都简陋(花花绿绿的不符合后端程序员的审美。) 三,无他
相信我,注册了域名,买了云主机,会加强开发动力。
相信我,没有云主机,本地服务也可以完成所有开发和效果展示。
遇到的问题:
- 文章的排版,简直惨不忍睹。代码块, markdown的正确使用迫在眉睫
还要做些什么?
- or 日志完善
- session 在前后交互的使用 --> 用户信息挂钩(设备id?)
- 文章索引
- 页面内位置跳转
- 回到顶部
- 点赞功能(交互页面的行为。)
- 留言 (插件,三方等等)
- 理解hugo,定制前端
- 访问路径/二级域名使用
- 访问日志。服务器安全
做个自己的云盘,上传,下载 爬虫 --> 考据 大芒果 MaNGOS VS TrinityCore electron react