--
:
--
:
--
hugo-teek is loading...
构建与部署
最后更新于:
📦 构建与部署
本地构建
1# 构建生产版本
2make build
3
4# 或直接使用 Hugo
5./hugo --source=hugo-teek-site --minify
构建产物位于 hugo-teek-site/public/ 目录。
部署到服务器
方式1: 静态文件部署
1# 构建
2make build
3
4# 上传到服务器
5rsync -avz hugo-teek-site/public/ user@server:/var/www/html/
方式2: Nginx 配置
1server {
2 listen 80;
3 server_name yourdomain.com;
4 root /var/www/html;
5 index index.html;
6
7 location / {
8 try_files $uri $uri/ /index.html;
9 }
10
11 # 开启 Gzip 压缩
12 gzip on;
13 gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
14}
方式3: GitHub Pages
创建 .github/workflows/deploy.yml:
1name: Deploy Hugo site to Pages
2
3on:
4 push:
5 branches: ["main"]
6 workflow_dispatch:
7
8permissions:
9 contents: read
10 pages: write
11 id-token: write
12
13jobs:
14 build:
15 runs-on: ubuntu-latest
16 steps:
17 - name: Checkout
18 uses: actions/checkout@v4
19
20 - name: Setup Hugo
21 uses: peaceiris/actions-hugo@v2
22 with:
23 hugo-version: '0.150.0'
24 extended: true
25
26 - name: Setup Go
27 uses: actions/setup-go@v4
28 with:
29 go-version: '1.21'
30
31 - name: Build
32 run: |
33 make install-deps
34 make build
35
36 - name: Upload artifact
37 uses: actions/upload-pages-artifact@v2
38 with:
39 path: ./hugo-teek-site/public
40
41 deploy:
42 environment:
43 name: github-pages
44 url: ${{ steps.deployment.outputs.page_url }}
45 runs-on: ubuntu-latest
46 needs: build
47 steps:
48 - name: Deploy to GitHub Pages
49 id: deployment
50 uses: actions/deploy-pages@v2
方式4: Docker 部署
创建 Dockerfile:
1FROM hugomods/hugo:exts as builder
2
3WORKDIR /src
4COPY . .
5RUN make build
6
7FROM nginx:alpine
8COPY --from=builder /src/hugo-teek-site/public /usr/share/nginx/html
9EXPOSE 80
构建并运行:
1docker build -t hugo-teek-blog .
2docker run -d -p 80:80 hugo-teek-blog
📡
👤
作者:
余温Gueen
🌐
版权:
本站文章除特别声明外,均采用
CC BY-NC-SA 4.0
协议,转载请注明来自
余温Gueen Blog!
推荐使用微信支付

推荐使用支付宝
