{"id":32692861,"url":"https://github.com/yeboyzq/authgate-nginx","last_synced_at":"2026-05-15T01:03:05.784Z","repository":{"id":321762844,"uuid":"1085121543","full_name":"yeboyzq/authgate-nginx","owner":"yeboyzq","description":"带有Nginx身份验证的Go网关应用程序，目前基于LDAP。","archived":false,"fork":false,"pushed_at":"2025-10-31T10:15:51.000Z","size":373,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-31T12:13:32.486Z","etag":null,"topics":["gateway","go","ldap","nginx"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mulanpsl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yeboyzq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T16:00:37.000Z","updated_at":"2025-10-31T10:15:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yeboyzq/authgate-nginx","commit_stats":null,"previous_names":["yeboyzq/authgate-nginx"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/yeboyzq/authgate-nginx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboyzq%2Fauthgate-nginx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboyzq%2Fauthgate-nginx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboyzq%2Fauthgate-nginx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboyzq%2Fauthgate-nginx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeboyzq","download_url":"https://codeload.github.com/yeboyzq/authgate-nginx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboyzq%2Fauthgate-nginx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282166162,"owners_count":26625189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-01T02:00:06.759Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gateway","go","ldap","nginx"],"created_at":"2025-11-01T16:02:03.267Z","updated_at":"2026-05-15T01:03:05.748Z","avatar_url":"https://github.com/yeboyzq.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AuthGate-Nginx\n\n\u003e **Guard the Data Gateway. Define the Security Perimeter.**  \n\u003e **守护数据入口，定义安全边界**\n\n[![Go Version](https://img.shields.io/badge/Go-1.24%2B-blue)](https://golang.org)\n[![License](https://img.shields.io/badge/License-Mulan\u0026ensp;PSL\u0026ensp;v2-green)]((https://opensource.org/license/mulanpsl-2-0))\n\nAuthGate-Nginx 是一个基于 Go 语言构建的轻量级、高性能身份验证网关。它作为 Nginx 的 `auth_request` 模块的后端，为您的 Web 应用和服务提供集中的、基于 LDAP 的身份验证层。\n\n## ✨ 特性\n\n* 🔐 **集中式 LDAP 认证**：无缝集成您的企业 LDAP/Active Directory，实现统一的用户登录。\n* 🚀 **高性能**：得益于 Go 语言的并发特性，提供极低的认证延迟。\n* 🔒 **安全第一**：专注于安全边界，保护您的后端应用和数据入口。\n* 🛠️ **与 Nginx 无缝集成**：通过标准的 `ngx_http_auth_request_module` 工作，配置简单。\n* ⚙️ **易于配置**：通过简单的 YAML 配置文件和环境变量进行管理。\n* 📦 **轻量级部署**：可编译为单一静态二进制文件，便于容器化（Docker）部署。\n\n## 🚀 快速开始\n\n### 前提条件\n\n* Go 1.25 或更高版本\n* 一个运行的 LDAP 服务器（例如 OpenLDAP, Active Directory）\n* Nginx（已启用 `--with-http_auth_request_module`）\n\n### 安装\n\n1. **使用 Go 安装**\n\n    ```bash\n    go install github.com/yeboyzq/authgate-nginx@latest\n    ```\n\n2. **从源码构建**\n\n    ```bash\n    git clone https://github.com/yeboyzq/authgate-nginx.git\n    cd authgate-nginx\n    env GOOS=linux GOARCH=amd64 go build -o ./build/authgate-nginx ./app\n    # 或\n    env GOOS=windows GOARCH=amd64 go build -o ./build/authgate-nginx.exe ./app\n    ```\n\n3. **使用 Docker**\n\n    ```bash\n    docker run -d \\\n      -v $(pwd)/config.yaml:/data/apps/conf.d/config.yaml \\\n      -p 8000:8000 \\\n      yeboyzq/authgate-nginx:latest\n    ```\n\n### 基础配置\n\n1. **创建配置文件** `config.yaml`：\n\n    ```yaml\n    base:\n        server:\n            protocol: http\n            domain: 127.0.0.1\n            port: 8000\n        jwt:\n            secret: xxxx\n        ldap:\n            url: ldap://localhost:389\n            bindDn: cn=admin,dc=example,dc=com\n            bindPassword: admin_password\n            userBaseDn: ou=users,dc=example,dc=com\n            filter: (uid=%s)\n    ......\n    ```\n\n2. **配置 Nginx**：\n\n    在您需要保护的 `location` 块中，添加 `auth_request` 指令。\n\n    ```nginx\n    server {\n        listen  443 ssl;\n        server_name  www.xxxx.com;\n        access_log  /data/logs/nginx/www_xxxx_com-access.log main;\n        ......\n\n        # 认证设置\n        location  = /nginx/api/verify {\n            internal;\n            proxy_pass  http://127.0.0.1:8000;\n            proxy_pass_request_body  off;\n            proxy_set_header  Content-Length \"\";\n            proxy_set_header  Cookie $http_cookie;\n            proxy_set_header  X-Original-URI $request_uri;\n            proxy_set_header  X-Original-Method $request_method;\n        }\n        location  = /nginx/login {\n            proxy_pass  http://127.0.0.1:8000;\n            proxy_set_header  Host $host;\n            proxy_set_header  X-Real-IP $remote_addr;\n            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;\n            proxy_set_header  X-Forwarded-Proto $scheme;\n        }\n        location  ~ ^/nginx {\n            proxy_pass  http://127.0.0.1:8000;\n            proxy_pass_header  Set-Cookie;\n            proxy_set_header  Cookie $http_cookie;\n            proxy_set_header  Host $host;\n            proxy_set_header  X-Real-IP $remote_addr;\n            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;\n            proxy_set_header  X-Forwarded-Proto $scheme;\n        }\n\n        location  / {\n            # 指定认证URL\n            auth_request  /nginx/api/verify;\n            auth_request_set  $auth_user $upstream_http_x_auth_user;\n            proxy_set_header  Cookie $http_cookie;\n            proxy_set_header  X-Auth-User $auth_user;\n            # 如果身份验证服务返回401则重定向到登录页面\n            error_page  401 =302 /nginx/login?redirect=$request_uri;\n\n            proxy_pass  http://127.0.0.1:8080/;\n            ......\n        }\n    }\n    ```\n\n3. **运行 AuthGate-Nginx**：\n\n    ```bash\n    ./authgate-nginx start -config config.yaml\n    ```\n\n现在，访问 `your-app.example.com` 将会通过 AuthGate-Nginx 进行 LDAP 身份验证。\n\n## ⚙️ 详细配置\n\nAuthGate-Nginx 支持通过配置文件和环境变量进行灵活配置。\n\n### 配置文件示例 (YAML)\n\n[config-example.yaml](./config-example.yaml)\n\n### 环境变量\n\n所有配置都可以通过环境变量覆盖，格式为 `APP_BASE_SITENAME`。\n\n```bash\nexport APP_BASE_SITENAME=\"AuthGate-Nginx\"\nexport APP_BASE_SERVER_PORT=8000\n```\n\n## 🏗️ 架构概述\n\n```text\n+----------+      +-------------+      +-----------------+      +-------------+\n|  Client  | ---\u003e |   Nginx     | ---\u003e | AuthGate-Nginx  | ---\u003e |  LDAP/AD    |\n| (Browser)|      | (Frontend)  |      |  (Auth Gateway) |      |   Server    |\n+----------+      +-------------+      +-----------------+      +-------------+\n                       ^                                              |\n                       | (X-User Header)                              |\n                       |                                              |\n                +-------------+                              (验证用户凭证)\n                | Backend App |\n                +-------------+\n```\n\n1. 用户请求访问受保护的资源。\n2. Nginx 的 `auth_request` 模块向 AuthGate 的 `/validate` 端点发起子请求。\n3. AuthGate 从请求头（如 `Authorization: Basic ...`）中提取凭据。\n4. AuthGate 使用这些凭据绑定到 LDAP 服务器进行验证。\n5. 如果认证成功，AuthGate 返回 `200 OK` 并附带用户信息头；失败则返回 `401 Unauthorized`。\n6. Nginx 根据响应决定是继续代理请求到后端应用还是拒绝访问。\n\n## 🤝 如何贡献\n\n我们欢迎并感谢所有的贡献！请随时提交 Issue 或 Pull Request。\n\n1. Fork 本仓库\n2. 创建您的功能分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 开启一个 Pull Request\n\n## 📄 许可证\n\n本项目基于 `木兰宽松许可证， 第2版` 开源 - 查看 LICENSE 文件了解详情。\n\n___\n\n**AuthGate-Nginx** - Guard the Data Gateway. Define the Security Perimeter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeboyzq%2Fauthgate-nginx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeboyzq%2Fauthgate-nginx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeboyzq%2Fauthgate-nginx/lists"}