创建新的站点hugo new site flygull
监控目录,实时构建网页cd flygull; hugo server --noHTTPCache -ws ./
hugo服务器
# 默认是 127.0.0.1,
# --bind=0.0.0.0 将可以绑定到所有接口,
# --disableLiveReload=true 关闭热部署
$ hugo server --baseURL=http://yoursite.org/ \
--port=80 \
--appendPort=false \
--bind=87.245.198.50
打印日志到文件 hugo server --noHTTPCache --log=true --logFile="./hugo.log" -ws ./
baseURL = "https://flygull.top/"
languageCode = "zh-CN"
defaultContentLanguage = "zh"
title = "Hugo Learn Documentation"
theme = "hugo-theme-learn"
themesdir = "./themes"
metaDataFormat = "yaml"
defaultContentLanguageInSubdir= true
[params]
editURL = "https://github.com/matcornic/hugo-theme-learn/edit/master/exampleSite/content/"
description = "Documentation for Hugo Learn Theme"
author = "Mathieu Cornic"
showVisitedLinks = true
disableBreadcrumb = false
disableNextPrev = false
disableLandingPageButton = true
disableMermaid = false
customMermaidURL = "https://unpkg.com/mermaid@8.8.0/dist/mermaid.min.js"
titleSeparator = "::"
[outputs]
home = [ "HTML", "RSS", "JSON"]
[Languages]
[Languages.zh]
title = "Hugo 主题的 Learn 文档"
weight = 1
languageName = "简体中文"
landingPageURL = "/zh-cn"
landingPageName = "<i class='fas fa-home'></i> 家"
[[Languages.zh.menu.shortcuts]]
name = "<i class='fab fa-fw fa-github'></i> GitHub 仓库"
identifier = "ds"
url = "https://github.com/matcornic/hugo-theme-learn"
weight = 10
[[Languages.zh.menu.shortcuts]]
name = "<i class='fas fa-fw fa-camera'></i> 展示区"
url = "/showcase"
weight = 11
[[Languages.zh.menu.shortcuts]]
name = "<i class='fas fa-fw fa-bookmark'></i> Hugo 文档"
identifier = "hugodoc"
url = "https://gohugo.io/"
weight = 20
[[Languages.zh.menu.shortcuts]]
name = "<i class='fas fa-fw fa-bullhorn'></i> 鸣谢"
url = "/credits"
weight = 30
[Languages.en]
title = "Documentation for Hugo Learn Theme"
weight = 2
languageName = "English"
landingPageURL = "/en"
landingPageName = "<i class='fas fa-home'></i> Home"
[[Languages.en.menu.shortcuts]]
name = "<i class='fab fa-fw fa-github'></i> GitHub repo"
identifier = "ds"
url = "https://github.com/matcornic/hugo-theme-learn"
weight = 10
[[Languages.en.menu.shortcuts]]
name = "<i class='fas fa-fw fa-camera'></i> Showcases"
url = "showcase"
weight = 11
[[Languages.en.menu.shortcuts]]
name = "<i class='fas fa-fw fa-bookmark'></i> Hugo Documentation"
identifier = "hugodoc"
url = "https://gohugo.io/"
weight = 20
[[Languages.en.menu.shortcuts]]
name = "<i class='fas fa-fw fa-bullhorn'></i> Credits"
url = "/credits"
weight = 30
[[Languages.en.menu.shortcuts]]
name = "<i class='fas fa-tags'></i> Tags"
url = "/tags"
weight = 30
hugo new --kind chapter hugo/_index.zh.md
hugo new --kind chapter hugo/_index.en.md
hugo new hugo/001_hugo.zh.md
hugo new hugo/001_hugo.en.md
添加NGINX的yum源vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=0
enabled=1
安装yum install nginx
修改配置文件/etc/nginx/nginx.conf
user nginx nginx # 设置nginx的启动用户和用户组
# http块中添加如下指令
http {
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
server_tokens off; # nginx 不显示版本信息
# php配置
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#gzip on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
}
修改/etc/nginx/conf.d/default.conf
server {
listen 80; # 监听端口
server_name flygull.top;
return 301 https://$host$request_uri;# 强转https
}
# HTTPS server
server {
# listen 443 ssl http2;
listen 443 ssl;
server_name flygull.top;
# 证书配置
ssl_certificate /etc/letsencrypt/live/flygull.top/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/flygull.top/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/flygull.top/chain.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 强制转https
#add_header Strict-Transport-Security "max-age=31536000;includeSubdomains";
# 全局root
root /your_root_directory/public;
index index.html index.htm;
# https认证接口
# 下载letsencrypt git clone https://github.com/letsencrypt/letsencrypt
# letsencrypt-auto certonly -m your_email@qq.com --webroot -w /your_root_directory/cert -d flygull.top
location /.well-known {
# 该url的单独的root目录
root /your_root_directory/cert;
}
# hugo-blog
location / {
# 默认使用全局的root /public
# 尝试在uri和uri/处查找,找不到则指向index.html
try_files $uri $uri/ /zh/404.html$is_args$args;
}
# 自动部署,在public目录下创建hook目录存放webhook.php,请求时查找hook目录下的php文件
location ~ /hook/.*\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
}
}
升级系统自带的php版本
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php7yum install php70w-common php70w-fpm
修改配置文件vim /etc/php-fpm.d/www.conf
,将用户,用户组改为nginx
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
在your_root_directory/public/hook/中添加webhook脚本
<?php
/**
* 自动更新钩子
* 修改密钥及项目路径即可使用
**/
//以流的方式读取
$requestBody = file_get_contents("php://input");
if (empty($requestBody)) {
die('send fail');
}
//file_put_contents('./requestBody.log', $requestBody);
$requestBody = json_decode($requestBody,true);
//加密字符串
$secret_post = $requestBody['sign'];
//时间戳参数,单位毫秒级
$time_stamp = $requestBody['timestamp'];
//在WebHooks签名密钥一栏填写的密钥信息
$access_token = 'your gitee secret key';
//加密文档
//https://gitee.com/help/articles/4290
$secret_join = $time_stamp . "\n" . $access_token;
//file_put_contents('./join.log', $secret_join);
$base64 = base64_encode(hash_hmac('sha256', $secret_join, $access_token, true));
//file_put_contents('./base64.log' , $base64);
//看推送的是哪个分支就构建哪个分支
//如有需要可以更改规则,比如屏蔽某些分支不构建
$branch = str_replace('refs/heads/', '', $requestBody['ref']);
//file_put_contents('./branch.log' , $branch);
$requestBody = null;
// 打开网站目录下的hooks.log文件 需要在服务器上创建 并给写权限
$fs = fopen('./deploy_webhooks_pull.log', 'a');
fwrite($fs, date('Y-m-d H:i:s') . ' ================ Update Start ===============' . PHP_EOL);// 请求ip
$client_ip = $_SERVER['REMOTE_ADDR'];
// 把请求的IP和时间写进log
fwrite($fs, date('Y-m-d H:i:s') . ' Request on [' . date("Y-m-d H:i:s") . '] from [' . $client_ip . ']' . PHP_EOL);
// 验证token 有错就写进日志并退出
if ($base64 !== $secret_post) {
fwrite($fs, date('Y-m-d H:i:s') . " Invalid token [{$client_token}]" . PHP_EOL);
$fs and fclose($fs);
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
exit;
}
// 如果有需要 可以打开下面,把传送过来的信息写进log 可用于调试,测试成功后注释即可
// fwrite($fs, 'Data: ' . print_r($data, true) . PHP_EOL);
// 执行shell命令并把返回信息写进日志
// 权限问题解决:
// 1. visudo 添加`nginx ALL=NOPASSWD:/usr/bin/git,/your_hugo_directory/hugo`让nginx用户有权限免密执行两个命令
// 2. 修改your_root_directory,blog_directory目录的所属权 chown -R nginx:nginx blog_directory/
$output = shell_exec('cd /your_blog_directory/ && sudo /usr/bin/git pull origin master 2<&1 && cd blog_directory && sudo /usr/your_hugo_directory/hugo && \cp -rf public/ /your_root_directory/ && echo success');fwrite($fs, date('Y-m-d H:i:s') . 'Info:' . print_r($output, true) . PHP_EOL);
fwrite($fs, date('Y-m-d H:i:s') . '================ Update End ===============' . PHP_EOL . PHP_EOL);
$fs and fclose($fs);
// 调试时打开
//echo json_encode($output);
参考:
php安装:https://www.cnblogs.com/chenliang725/p/12575926.html
webhook脚本:https://www.cnblogs.com/wscsq789/p/13139031.html
https://flygull.top/hook/webhook.php
├── root_directory
│ ├── cert
│ └── public
│ └── hook
│ └── webhook.php
└── blog_directory