{"id":13836600,"url":"https://github.com/mauricioabreu/dynamic-upstream-learning","last_synced_at":"2026-02-16T06:01:52.240Z","repository":{"id":173685303,"uuid":"651122933","full_name":"mauricioabreu/dynamic-upstream-learning","owner":"mauricioabreu","description":"Playing with NGINX lua balancing features","archived":false,"fork":false,"pushed_at":"2023-06-10T13:20:49.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T10:39:44.196Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mauricioabreu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-06-08T14:43:31.000Z","updated_at":"2025-02-09T17:56:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"b32fe574-f913-43c3-afbe-c36c57d9bbc6","html_url":"https://github.com/mauricioabreu/dynamic-upstream-learning","commit_stats":null,"previous_names":["mauricioabreu/dynamic-upstream-learning"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mauricioabreu/dynamic-upstream-learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioabreu%2Fdynamic-upstream-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioabreu%2Fdynamic-upstream-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioabreu%2Fdynamic-upstream-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioabreu%2Fdynamic-upstream-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauricioabreu","download_url":"https://codeload.github.com/mauricioabreu/dynamic-upstream-learning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricioabreu%2Fdynamic-upstream-learning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29501359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T05:57:17.024Z","status":"ssl_error","status_checked_at":"2026-02-16T05:56:49.929Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-08-04T15:00:50.656Z","updated_at":"2026-02-16T06:01:52.222Z","avatar_url":"https://github.com/mauricioabreu.png","language":"Dockerfile","readme":"# Dynamic Upstream learning\n\nJust playing with some NGINX lua balancing features\n\n## Motivation\n\nI wanted to learn more about how to balance requests to upstreams in a more dynamic way. What if I need to route some requests to one upstream A, and some other requests to upstream B.\n\n## Problem\n\nYou have given the task of balancing requests. If a request with `/foo/something` comes in you need to balance the requests between to server A (primary) and pick the server B (backup) when A does not work.\n\nOk, it could be a static upstream in NGINX, right? Yes, you are right but rabbits don't come easy.\n\nServers come and go, and we need to be ready to deliver different hosts for different requests.\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant NGINX\n    participant Server1 as 127.0.0.2\n    participant Server2 as 127.0.0.3\n\n    User-\u003e\u003eNGINX: Request /foo/something\n    NGINX-\u003e\u003eServer1: Proxy Pass\n    Server1-\u003e\u003eNGINX: Success Response\n    NGINX-\u003e\u003eUser: Forward Success Response\n\n    User-\u003e\u003eNGINX: Request /foo/something\n    NGINX-\u003e\u003eServer1: Proxy Pass\n    Server1--\u003e\u003eNGINX: Failure Response\n    NGINX-\u003e\u003eServer2: Proxy Pass\n    Server2-\u003e\u003eNGINX: Success Response\n    NGINX-\u003e\u003eUser: Forward Success Response\n```\n\n## Running\n\nDependencies:\n\n* [just](https://github.com/casey/just)\n* [docker compose](https://docs.docker.com/compose/)\n\n```console\n$ just -l\n\nAvailable recipes:\n    rebuild # Rebuild all containers\n    reload  # Reload NGINX\n    run     # Start origin and upstreams API\n    stop    # Stop origin and upstreams API\n```\n\n```console\n$ just run\n```\n\nNow you have NGINX running on 8080 and upstreams API on 8081.\n\nGo ahead and make a request for an existing upstream:\n\n```\ncurl -v http://localhost:8080/upstream1/foo\n```\n\nThen for an upstream that does not exist:\n\n```\ncurl -v http://localhost:8080/upstream2/foo\n```\n\nCompare the logs and the HTTP responses.\n","funding_links":[],"categories":["Dockerfile"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauricioabreu%2Fdynamic-upstream-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauricioabreu%2Fdynamic-upstream-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauricioabreu%2Fdynamic-upstream-learning/lists"}