使用 Docker 部署 Gogs

本文分享如何使用 Docker 部署 Gogs

如果您是第一次阅读该系列文章,建议优先阅读 Docker 部署项目说明及索引

前置操作

提前创建好 Gogs 的数据库,Gogs 支持 MySQL、PostgreSQL、SQLite3 或 TiDB(MySQL 协议)数据库。

Docker Compose

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
version: "3.9"

services:
  gogs:
    image: gogs/gogs:latest
    container_name: gogs
    hostname: gogs
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - /docker/gogs:/data
    environment:
      - TZ=Asia/Shanghai
networks:
  default:
    external: true
    name: rod

使用 Gogs

打开链接: http://localhost:3000 按指引安装配置 Gogs 即可。

NPM 反向代理配置

此处以 https://gogs.example.com 为例

如果未部署 NPM,可参考文章:使用 Docker 部署 Nginx Proxy Manager

Details

  • Domain Names: gogs.example.com
  • Scheme: http
  • Forward Hostname/IP: 127.0.0.1 (如果 NPM 未使用 HOST,则使用容器的 hostname: gogs)
  • Forward Port: 3000
  • Cache Assets: ✅

SSL

  • 选择你已经配置好的 SSL Certificate,如 *.example.com, example.com
  • Force SSL: ✅
  • HTTP/2 Support: ✅

Advanced

1
2
3
4
5
6
7
8
location / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    proxy_pass $forward_scheme://$server:$port;
}

参考链接

如果本文对您有所帮助,欢迎打赏支持作者!

Licensed under CC BY-NC-SA 4.0
最后更新于 2026-08-06 15:00
使用 Hugo 构建
主题 StackJimmy 设计