{"id":16151303,"url":"https://github.com/terrygeng/nginx-simple-login","last_synced_at":"2026-04-30T07:35:17.489Z","repository":{"id":55663702,"uuid":"321359280","full_name":"TerryGeng/nginx-simple-login","owner":"TerryGeng","description":"A self-hosted, lightweight authentication service backend designed to work with nginx's auth_request.","archived":false,"fork":false,"pushed_at":"2021-04-04T09:33:47.000Z","size":673,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T17:10:19.590Z","etag":null,"topics":["authentication-backend","nginx"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TerryGeng.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}},"created_at":"2020-12-14T13:40:09.000Z","updated_at":"2025-05-27T15:16:29.000Z","dependencies_parsed_at":"2022-08-15T05:50:59.631Z","dependency_job_id":null,"html_url":"https://github.com/TerryGeng/nginx-simple-login","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TerryGeng/nginx-simple-login","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryGeng%2Fnginx-simple-login","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryGeng%2Fnginx-simple-login/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryGeng%2Fnginx-simple-login/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryGeng%2Fnginx-simple-login/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TerryGeng","download_url":"https://codeload.github.com/TerryGeng/nginx-simple-login/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TerryGeng%2Fnginx-simple-login/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259750742,"owners_count":22905934,"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","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":["authentication-backend","nginx"],"created_at":"2024-10-10T00:55:50.027Z","updated_at":"2026-04-30T07:35:17.458Z","avatar_url":"https://github.com/TerryGeng.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nginx-simple-login\n\nA lightweight authentication service backend designed to work\nwith nginx's auth_request.\n\n![Screenshot](screenshots/login.jpg)\n\n## Features\n\n- auth_request handler,\n- Authentication page,\n- Local user database.\n\n\n## Usage\n\n### Basic\n\n1. Clone this repo.\n\n2. Install this package by `pip install .` (recommended to\n install in a `virtualenv`).\n \n3. Create `config.yaml`, follows `config.example.yaml`. A minimal version:\n```yaml\nuser_table: users.yaml\nsite_name: Restrict Area\nlogfile: /var/log/nslogin.py\nlogin_life_time: 2592000  # 30 days\n```\n\n4. Add user with `nslogin-user` command, e.g.\n```bash\nnslogin-user --config config.yaml --add --name terry\n```\n\n5. Run the daemon of _nslogin_ `nslogind --config config.yaml`.\n\n6. Edit `nginx.conf`, \n```nginx\n    location / {\n        auth_request /nslogin/auth;  # \u003c\u003c\u003c insert auth_request at locations that require auth\n        root   /srv/http;\n        index  index.html index.htm;\n    }\n\n    location ^~ /nslogin {\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 /nslogin/auth {\n            proxy_pass http://127.0.0.1:8222/auth;\n            proxy_pass_request_body off;\n            proxy_set_header Content-Length \"\";\n        }\n\n        location /nslogin {\n            rewrite /nslogin/(.*) /$1  break;\n            proxy_pass http://127.0.0.1:8222;\n        }\n    }\n\n    error_page 401 = @error401;\n    error_page 403 = @error403;\n\n    location @error401 {\n        return 302 http://$http_host/nslogin/?redirect=http://$http_host$request_uri;\n    }\n    location @error403 {\n        return 302 http://$http_host/nslogin/403;\n    }\n```\n\n7. Reload nginx and enjoy.\n\n### Privilege system\n\nSometimes one may want to restrict one user to access a specific path. This can\nbe achieved by the privilege system of _nslogin_.\n\n1. Add user with privileges set as\n```bash\nnslogin-user --config config.yaml --add --name terry --privileges A, B\nnslogin-user --config config.yaml --add --name alice --privileges A \nnslogin-user --config config.yaml --add --name bob --privileges B \n```\nor, in short,\n```bash\nnslogin-user -a -n terry -pr A, B\nnslogin-user -a -n alice -pr A\nnslogin-user -a -n bob -pr B\n```\n\n2. Edit `nginx.conf`\n```nginx\n    location /kitchen {\n        auth_request /nslogin/auth/A; # \u003c\u003c\u003c 'A' is the privilege requested to access this location\n        root   /srv/http;\n        index  index.html index.htm;\n    }\n    location /bedroom {\n        auth_request /nslogin/auth/B; # \u003c\u003c\u003c 'B' is the privilege requested to access this location\n        root   /srv/http;\n        index  index.html index.htm;\n    }\n```\n\nThis configuration allows `alice` to access `/kitchen` and `bob` to access \n`/bedroom` and grants `terry` the access to both locations.\n\n\n### Register\nSometimes one would like to allow others to register to the server with a valid\ninvitation code. Register function can be enabled by putting the following snippet\ninto the `config.yaml`\n```yaml\nregister:\n  enabled: true\n  use_invitation_code: true\n  dispose_used_invitation_code: true\n  invitation_code_file: invitations.yaml\n```\n\nwhere `invitations.yaml` is a list of invitation codes. A handy way to generate\nsome is\n```bash\nfor i in {1..5}; do echo \"- $(dd if=/dev/random bs=9 count=1 2\u003e/dev/null | base64)\"; done \u003e invitations.yaml\n```\n\n\n### Escape request URL\nWhen redirection to the login page, the original URL is passed as a `GET` parameter:\n```nginx\n    location @error401 {\n        return 302 http://$http_host/nslogin/?redirect=http://$http_host$request_uri;\n    }\n```\n\nIf `$request_uri` includes other `GET` parameters, they will be ignored. In\norder to properly encode `$request_uri`, one needs to install [lua-nginx-module](\nhttps://github.com/openresty/lua-nginx-module) because nginx doesn't have the ability\nto deal with complicated rewrite rules. Then use `rewrite_by_lua_block`:\n```nginx\n    location @error401 {\n        rewrite_by_lua_block {\n                return ngx.redirect(\"http://\" .. ngx.var.http_host .. \"/nslogin/?redirect=\" .. ngx.escape_uri(ngx.var.request_uri))\n        }\n    }\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrygeng%2Fnginx-simple-login","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterrygeng%2Fnginx-simple-login","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrygeng%2Fnginx-simple-login/lists"}