Skip to content

seqyuan/goprox

Repository files navigation

GoProx

一台 Linux 服务器,一个 Web 入口,每人管理自己的 Jupyter / RStudio / 内网服务。

GoProx 是面向实验室、登录节点的多用户认证反向代理网关,用 Go 语言编写。运维启动一个共享网关,普通用户登录网页管理转发(添加卡片、拖动排序),无需每人记不同端口。

安装

go install github.com/seqyuan/goprox@latest

安装完成后,goprox 会出现在 $GOPATH/bin 目录下(通常是 ~/go/bin),确保该目录在 PATH 中:

export PATH=$PATH:$(go env GOPATH)/bin

快速开始

# ① 运维:启动网关
./goprox --port 1908

# ② 用户 alice:设密码
./goprox passwd

# ③ 浏览器管理
http://lab.example.com:1908/  →  登录  →  点 + 添加、拖动排序、点击卡片访问

命令参考

goprox [options]                # 启动网关(前台)
goprox start [options]          # 后台启动
goprox stop [options]           # 停止网关
goprox status [options]         # 查看状态
goprox passwd [options]         # 设置登录密码

Options:
  -s, --state <path>    状态文件(默认 ~/.local/state/goprox/state.yaml)
  -c, --config <path>   用户配置(默认 ~/.config/goprox/config.yaml)
  --host <host>         监听地址(默认 0.0.0.0)
  --port <port>         监听端口(默认 1908)

工作流程

运维启动 goprox(共享网关)
        │
        ▼
用户 goprox passwd(设密码)
        │
        ├──────────────────────┐
        ▼                      ▼
网页:+ 添加 / 拖动 / 删除
        │                      │
        └──────────┬───────────┘
                   ▼
        写入 ~/.config/goprox/config.yaml
                   ▼
        daemon 扫描加载(约 10 秒刷新)
                   ▼
        浏览器登录,访问 /proxy/<用户>/<服务>/

配置文件

用户配置 (~/.config/goprox/config.yaml)

auth:
  password_hash: "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
services:
  - id: jupyter
    name: "Jupyter Lab"
    description: "交互式笔记本"
    host: "127.0.0.1"
    port: 8888
    path: "/jupyter"
    websocket: true
    category: "开发工具"
    order: 0

网关状态 (~/.local/state/goprox/state.yaml)

server:
  host: "0.0.0.0"
  port: 1908
auth:
  session_secret: "<auto-generated>"
  session_ttl: 86400
users:
  home_prefix: "/home"

WebSocket 代理

Jupyter、RStudio 等需要 WebSocket 的服务,添加时必须勾选 WebSocket,或设置 websocket: true

关闭此选项后,WebSocket 升级请求会被拒绝(返回 403)。

后端服务配置指南

代理能正确转发 HTTP 请求,但后端服务生成的页面链接默认是绝对路径(如 /lab),需要配置服务的 base_url 使其与代理前缀一致。

Jupyter Lab

jupyter lab \
  --ip=0.0.0.0 \
  --port=8888 \
  --NotebookApp.base_url='/proxy/<用户>/<服务路径>/' \
  --NotebookApp.token='' \
  --no-browser

或在 ~/.jupyter/jupyter_lab_config.py 中:

c.ServerApp.base_url = '/proxy/用户名/jupyter/'
c.ServerApp.token = ''

Jupyter Notebook

jupyter notebook \
  --ip=0.0.0.0 \
  --port=8888 \
  --NotebookApp.base_url='/proxy/<用户>/<服务路径>/' \
  --NotebookApp.token='' \
  --no-browser

RStudio Server

/etc/rstudio/rserver.conf 中:

www-address=127.0.0.1
www-port=8787
www-root-path=/proxy/<用户>/rstudio/

Code Server (VS Code)

code-server \
  --bind-addr 127.0.0.1:8080 \
  --auth none \
  --base-path '/proxy/<用户>/code/'

注意:将 <用户> 替换为 Linux 用户名,<服务路径> 替换为卡片中设置的 path 值。

License

MIT

About

Multi-service authenticated reverse proxy hub in Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors